为什么我的松露部署因资金不足而失败?

Why my truffle deploy fails due to insufficient funds?

我的钱包里有足够的 ETH,但是由于不合逻辑的原因迁移到主网失败 - 资金不足。

Truffle 的成本计算逻辑很奇怪——它部署了初始迁移和我的合约 (Nft),然后抱怨钱包中剩余的余额低于总的前期成本。感谢您帮助我理解这一点。

不合逻辑的错误:0.1381 ETH 低于前期成本 0.2755 ETH

松露-config.js

const HDWalletProvider = require('truffle-hdwallet-provider')
...
live: {
      provider: () => new HDWalletProvider(MNEMONIC_LIVE, LIVE_URL),
      network_id: 1, 
      gas: 3450000,        
      gasPrice: web3.utils.toWei('79', 'gwei'),   
      confirmations: 1,    
      timeoutBlocks: 200,  
      skipDryRun: false,     
      networkCheckTimeout:1000000
    },

迁移干-运行日志

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

   Deploying 'Migrations'
   ----------------------
   > block number:        12232671
   > block timestamp:     1618329800
   > account:             0xbb467DA83d9DB2F10Bb5E6d5C4b48121a62FB80E
   > balance:             0.379524194
   > gas used:            235234 (0x396e2)
   > gas price:           79 gwei
   > value sent:          0 ETH
   > total cost:          0.018583486 ETH

   -------------------------------------
   > Total cost:         0.018583486 ETH


3_nft_deploy.js
================

   Deploying 'Nft'
   ----------------
   > block number:        12232673
   > block timestamp:     1618330490
   > account:             0xbb467DA83d9DB2F10Bb5E6d5C4b48121a62FB80E
   > balance:             0.138160076
   > gas used:            3027724 (0x2e330c)
   > gas price:           79 gwei
   > value sent:          0 ETH
   > total cost:          0.239190196 ETH


Error: sender doesn't have enough funds to send tx. The upfront cost is: 272550000000000000 and the sender's account only has: 138160076000000000
    at Migration._deploy (/home/roman/.npm-global/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:103:1)
    at process._tickCallback (internal/process/next_tick.js:68:7)
Truffle v5.2.6 (core: 5.2.6)
Node v10.19.0

我遇到了同样的问题,我可以联系 truffle 支持团队,他们知道这个问题,答案如下:

Please note we added a new issue about it: 
https://github.com/trufflesuite/truffle/issues/3992 
please follow it directly on GitHub

无论如何,你可以避免运行 dryrun 来部署迁移或者做我所做的调整 gas 和 gasPrice 以降低 tx 成本并为我的钱包添加更多资金。

如果您正确处理 gas 和 gasPrice,您就不必担心钱包中的 Ether 超过您的实际需要。

我知道,这不是最好的解决方案,但很有效。