3

truffle.js:

var HDWalletProvider = require("truffle-hdwallet-provider");
var mnemonic = "";

module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 8545,
      network_id: "*" // Match any network id
    },
      rinkeby: {
      provider: function() { 
       return new HDWalletProvider(mnemonic, "https://rinkeby.infura.io/v3/");
      },
      network_id: 4,
      gasPrice: "450000000", 
    },
    live: {
      networkCheckTimeout: 100000, 
      provider: function() { 
       return new HDWalletProvider(mnemonic, "https://mainnet.infura.io/v3/");
      },
      network_id: 1,
      gasPrice: "450000000",

    },
  },
  compilers: {
    solc: {
      version: "0.8.4",

    },
  },
};


Successfully deploying to Rinkeby:

   > transaction hash:    
   > Blocks: 1            Seconds: 17
   > contract address:    
   > block number:        8751194
   > block timestamp:     1623504143
   > account:             
   > balance:             18.7469330662
   > gas used:            1476936 (0x168948)
   > gas price:           0.45 gwei
   > value sent:          0 ETH
   > total cost:          0.0006646212 ETH

   > Saving artifacts
   -------------------------------------
   > Total cost:        0.0006646212 ETH


Summary
=======
> Total deployments:   1
> Final cost:          0.0006646212 ETH

Error while deploying to mainnet:

Error:  *** Deployment Failed ***

"ContractName" could not deploy due to insufficient funds
   * Account:  
   * Balance:  991972954849359 wei
   * Message:  insufficient funds for gas * price + value
   * Try:
      + Using an adequately funded account
      + If you are using a local Geth node, verify that your node is synced.

    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:365:1
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at Migration._deploy (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:74:1)
    at Migration._load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:61:1)
    at Migration.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:212:1)
    at Object.runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:150:1)
    at Object.runFrom (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:110:1)
    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:87:1)
    at runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:263:1)
    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:226:1)
    at Command.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:136:1)
Truffle v5.2.4 (core: 5.2.4)
Node v14.15.0

My balance is clearly more than that required by the transaction. Why is this happening?

2

You need to re-calculate the amount of ETH you need for the mainnet deployment as follows:

deploymentCostInETH = gasAmount * gasPrice

deploymentCostInETH differs depending on the current gas price.

gasAmount is going to be the same for mainnet as it was for the testnet or any other network you deploy that specific contract to, which is 1476936. gasAmount depends on the contract's compiled bytecode.

gasPrice is what makes deploymentCostInETH differ across networks or over time, since it depends on the current gas price which depends on factors like network congestion.

Assuming today's average mainnet gas price (13 gwei = 13 * 10^9 wei = 13 * 10^-9 ETH), the calculation result would be:

deploymentCostInETH = 1476936 * 13 * 10^-9 = 0.019200168 ETH

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.