{"content":{"title":"Truffle 使用记录","body":"# 一. 配置链信息 \r\n\r\n在truffle-config中\r\n\r\n     \r\n```bsctest: {\r\n      provider: function() {\r\n          return new HDWalletProvider(\"钱包私钥\", \"RPCURL\") },\r\n      network_id: 97,\r\n      chain_id:97,\r\n      gasPrice: 10000000000000, \r\n      gas:50000000,\r\n      websockets: true,\r\n      timeoutBlock:1000,\r\n     },\r\n```\r\n[详细配置说明](https://learnblockchain.cn/docs/truffle/reference/configuration.html)\r\n# 二.遇到问题\r\n执行以下命令\r\n`truffle compile`\r\n`truffle migrate --network bsctest`\r\n\r\n```Compiling your contracts...\r\n===========================\r\n> Everything is up to date, there is nothing to compile.\r\n\r\n\r\nStarting migrations...\r\n======================\r\n> Network name:    'bsctest'\r\n> Network id:      97\r\n> Block gas limit: 50000000 (0x2faf080)\r\n\r\n\r\n1_deploy_contracts.js\r\n=====================\r\n\r\n   Deploying 'MetaCoin'\r\n   --------------------\r\n *** Deployment Failed ***\r\n\r\n\"MetaCoin\" -- transaction overpriced.\r\n\r\n\r\nExiting: Review successful transactions manually by checking the transaction hashes above on Etherscan.\r\n\r\n\r\nError:  *** Deployment Failed ***\r\n\r\n\"MetaCoin\" -- transaction overpriced.\r\n\r\n    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:331:1\r\n    at processTicksAndRejections (node:internal/process/task_queues:95:5)\r\n    at Migration._deploy (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:68:1)\r\n    at Migration._load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:54:1)\r\n    at Migration.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:202:1)\r\n    at Object.runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:142:1)\r\n    at Object.runFrom (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:107:1)\r\n    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:91:1)\r\n    at module.exports (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate/runMigrations.js:10:1)\r\n    at Object.module.exports [as run] (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate/run.js:41:1)\r\n    at runCommand (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/command-utils.js:184:1)\r\nTruffle v5.5.23 (core: 5.5.23)\r\nNode v18.15.0\r\n```\r\n 解决方案:更换了节点 就好了\r\n问题二\r\n\r\n```Starting migrations...\r\n======================\r\n> Network name:    'bsctest'\r\n> Network id:      97\r\n> Block gas limit: 50000000 (0x2faf080)\r\n\r\n\r\n1_deploy_contracts.js\r\n=====================\r\n\r\n   Deploying 'MetaCoin'\r\n   --------------------\r\n *** Deployment Failed ***\r\n\r\n\"MetaCoin\" -- tx fee (250000.00 ether) exceeds the configured cap (1.00 ether).\r\n\r\n\r\nExiting: Review successful transactions manually by checking the transaction hashes above on Etherscan.\r\n\r\n\r\nError:  *** Deployment Failed ***\r\n\r\n\"MetaCoin\" -- tx fee (250000.00 ether) exceeds the configured cap (1.00 ether).\r\n\r\n    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:331:1\r\n    at processTicksAndRejections (node:internal/process/task_queues:95:5)\r\n    at Migration._deploy (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:68:1)\r\n    at Migration._load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:54:1)\r\n    at Migration.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:202:1)\r\n    at Object.runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:142:1)\r\n    at Object.runFrom (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:107:1)\r\n    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:91:1)\r\n    at module.exports (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate/runMigrations.js:10:1)\r\n    at Object.module.exports [as run] (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate/run.js:41:1)\r\n    at runCommand (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/command-utils.js:184:1)\r\nTruffle v5.5.23 (core: 5.5.23)\r\nNode v18.15.0\r\n```\r\n解决方案:\r\n方案一: truffle migrate --network bsctest  --rpc.txfeecap 0 --rpc.gascap 0 (失败)[参考资料](https://blog.csdn.net/qq_39562468/article/details/121618247)\r\n\r\n方案二:更改配置\r\n\r\n```bsctest: {\r\n      provider: function() {\r\n          return new HDWalletProvider(\"XXXXX\",\r\n          \"https://data-seed-prebsc-2-s2.bnbchain.org:8545\") },\r\n      network_id: 97,\r\n      chain_id: 97,\r\n      gasPrice: 20e10, \r\n      gas: 25e6,\r\n      websockets: false,\r\n      timeoutBlock: 1000,\r\n     },\r\n```\r\n中的gas 直接去掉"},"author":{"user":"https://learnblockchain.cn/people/15926","address":"0x0ec50591bcc747833c08b8250e1334207d09b8a5"},"history":"QmZAGqGMqmFp44J7qC4mNs7jeDTxe48qk4pnA9bhVSnUkp","timestamp":1690794032,"version":1}