0

I have a simple 100-line contract with 6 functions that I want to deploy to the main net. When I deploy it to the Rinkeby test net through Truffle, I get the following result:

Summary
=======
> Total deployments:   2
> Final cost:          0.01959998 ETH

However, when I try to deploy to the main net, I get the following:

Message:  sender doesn't have enough funds to send tx. The upfront cost is: 260000000000000000 and the sender's account only has: 11370852144167560

This is equivalent to over $500 USD. Surely this can't be accurate?

Following is my Truffle config:

live: {
  networkCheckTimeout: 100000000,
  provider: function() {
    return new HDWalletProvider(
      privateKeys.split(','), // Array of account private keys
      `https://mainnet.infura.io/v3/${process.env.INFURA_API_KEY}`
    )
  },
  network_id: "1",
  gas: 4000000,
  gasPrice: 65000000000, // 65Gwei
},

I deployed the contract to the test net on Remix and the estimated fee was 6721074 gwei which is about $15 currently.

1

Ethereum requires to upfront gas * gasPrice for the transaction fee, it will return unused gas but the gas has to be paid in advance.

The config has gas = 4M and gasPrice = 65 gwei so for every transaction you have to have 4 * 10^6 * 65 * 10^9 = 26 * 10^16 wei = 0.26 ether.

Set gasPrice low enough in truffle-config (200k gas) and individually set the gas for every contract deployment and transaction in the migration scripts. Use ganache deployment to calculate how much each contract requires. For example if a contract requires 1234567 for deployment in ganache set to 1300000 in mainnet.

Also be aware that gasPrice is much higher in mainnet than in rinkeby, using a low gasPrice might cause truffle to timeout and it will think deployment failed.

3
  • I found out that the gas limit is about 200k and the gas price is hovering around 100 - 150 Gwei as I'm typing this, which makes it about $50 to $60 USD. Is it really this expensive to deploy a 100-line smart contract? I've tried to deploying with $40 USD and the transaction is stuck at pending for hours. I've tried deploying from Remix and Truffle both. – Kevvv Apr 9 at 21:30
  • @Kevvv It has always been expensive, now with the ether price soaring and high network usage it is more. Unless you have deep pockets deploy to mainnet only when needed. – Ismael Apr 9 at 22:01
  • Sorry I was wrong in the calculation. It's requiring 2 million gas limit, not 200k, which means I need 300 dollars to upload a contract? – Kevvv Apr 9 at 23:45

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.