Gas settings when deploying to mainnet

Hello Guys, I’m ready to deploy my contract to MainNet. I need some input so that the deployment would be smooth. Ive been using the gasPrice values in the truffl-config.js below when deploying to Ropsten. Do I need to adjust the gas and gasPrice values when I deploy to the MainNet? What would be the recommended values? Thanks in advance.

main: {
  provider: function() {
    return new HDWalletProvider(
      privateKeys.split(','), // Array of account private keys
      `https://main.infura.io/v3/${process.env.INFURA_PROJECT_ID}`// Url to an Ethereum Node
    )
  },
  gas: 5000000,
  gasPrice: 5000000000, // 5 gwei
  network_id: 1
},
ropsten: {
  provider: function() {
    return new HDWalletProvider(
      privateKeys.split(','), // Array of account private keys
      `https://ropsten.infura.io/v3/${process.env.INFURA_PROJECT_ID}`// Url to an Ethereum Node
    )
  },
  gas: 5000000,
  gasPrice: 5000000000, // 5 gwei
  network_id: 3
}
1 Like

Hi @JoeRiz,

I suggest looking at: https://docs.openzeppelin.com/learn/preparing-for-mainnet

The amount of gas required will be the same but the gas price will be very different.
Check services such as for the current gas prices:

You should calculate what the cost of deploying your contract will be. Depending on your contract and network congestion this could be in the region of $500-$1500

1 Like

Thank you. I got the gasPrice part. Regarding the gas: value in the truffle-config.js file, I saw that my contract uses 3228723 gas when I deployed it on ropsten, should I then change the gas value in the config file to also 3228723 when I deploy to mainner? Or do I need to increase that?

1 Like

Hi @JoeRiz,

I suggest rounding it up though I wouldn’t expect a difference in gas usage.

You can also use Truffle to do a dry run: https://www.trufflesuite.com/docs/truffle/reference/truffle-commands#migrate

1 Like

Okay just to really make sure so I dont screw up my deployment and also my funds :slight_smile:
Does this config setting look right?

  gas: 3300000, // per gas used when deployed in test 
  gasPrice: 132000000000, // 132 gwei (current cost in eth station)

And lastly, do I need to change the default timeoutBlocks?
Thanks!

1 Like

Hi @JoeRiz,

It looks ok, though I would test with a dry run in Truffle.

Network congestion has increased the gas price since you posted this so you may need some buffer. You should calculate how much this will be to deploy prior to deploying.

Truffle also deploys a Migrations contract when you use migrations.

Thanks. Yup I included the migrations contract in the gas used total above. Would you know whats the ideal time for deployment where gas cost would be cheaper?

1 Like

Hi @JoeRiz,

Have a look at historical gas prices on Gas Now to see lower cost times of day.

1 Like