简体   繁体   中英

Why my truffle deploy fails due to insufficient funds?

I have enough ETH in the wallet but migration to mainnet fails for illogical reason - not enough funds.

Truffle has strange logic of cost calculation - it deploys Initial migration and my contract (Nft) and then complains that the remaining balance left in the wallet is lower than total upfront cost. Thank you for helping me to understand this.

  • wallet balance: 0.3981 ETH
  • upfront cost (gas * price): 0.2755 ETH
  • deployment cost reported by Truffle: approx.0.26 ETH
  • remaining balance: 0.1381 ETH

Illogical Error: 0.1381 ETH is lower than upfront cost 0.2755 ETH

truffle-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
    },

Migration dry-run log

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

I had same problem and I was able to contact with truffle support team, they know the issue, here's the answer:

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

Anyways, you can avoid running dryrun to deploy migration or do what I did which was to adjust gas and gasPrice in order to reduce tx cost and add more funds to my wallet.

If you handle correctly gas and gasPrice, you should not be worried to have more Ethers in your wallet than you really need.

I know, It's not the best solution but works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM