Contract-Deployment

在 Polygon 主網上部署智能合約時的問題

  • February 27, 2022

我正在嘗試在 Polygon 主網上部署智能合約,但是當我使用 truffle 執行遷移命令時會發生這種情況

> Network name:    'matic'
> Network id:      137
> Block gas limit: 30176202 (0x1cc73ca)


1_initial_migration.js
======================

  Deploying 'Animals'
  -------------------
*** Deployment Failed ***

"Animals" -- transaction underpriced.


Exiting: Review successful transactions manually by checking the transaction hashes above on Etherscan.


Error:  *** Deployment Failed ***

"Animals" -- transaction underpriced.

   at /Users/nick/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:379:1
   at runMicrotasks (<anonymous>)
   at processTicksAndRejections (node:internal/process/task_queues:96:5)
   at Migration._deploy (/Users/nick/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:68:1)
   at Migration._load (/Users/nick/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:54:1)
   at Migration.run (/Users/nick/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:202:1)
   at Object.runMigrations (/Users/nick/node_modules/truffle/build/webpack:/packages/migrate/index.js:152:1)
   at Object.runFrom (/Users/nick/node_modules/truffle/build/webpack:/packages/migrate/index.js:117:1)
   at Object.runAll (/Users/nick/node_modules/truffle/build/webpack:/packages/migrate/index.js:121:1)
   at Object.run (/Users/nick/node_modules/truffle/build/webpack:/packages/migrate/index.js:86:1)
   at runMigrations (/Users/nick/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate/run.js:78:1)
   at Object.module.exports [as run] (/Users/nick/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate/run.js:44:1)
   at Command.run (/Users/nick/node_modules/truffle/build/webpack:/packages/core/lib/command.js:189:1)
Truffle v5.5.1 (core: 5.5.1)

這是我的 truffle-config.js

matic: {
       provider: () => new HDWalletProvider(mnemonic, `https://polygon-mainnet.g.alchemy.com/v2/key`),
       network_id: 137,
       confirmations: 2,
       timeoutBlocks: 200,
       skipDryRun: true
     },

低價交易通常意味著您的 gasPrice 太低,請嘗試在您的配置中設置自定義 gasPrice:https ://trufflesuite.com/docs/truffle/reference/configuration

您可以使用它來查看目前的 gas 價格是多少:https ://polygonscan.com/gastracker

請注意,gasPrice 以 wei 為單位

引用自:https://ethereum.stackexchange.com/questions/122673