Remix - Gas estimation failed

I want to write a standard contract using openzeppelin wizard. When I try to run my contract via Remix, I get a "Gas estimation failed" error. The standard gas value is 3000000, but the phrase "infinite gas 1120200 gas" appears in the contract. Does this mean that if I set the gas value in the Remix to 1120200, I can deploy?

When a transaction is estimated to cost K gas, you can use any value >= K in order to execute it.

Your wallet will be charged ONLY the gas which was actually used for executing the transaction.

So in terms of cost, it shouldn't really matter how much gas you specify above the estimation.

There are nevertheless a couple of downsides for specifying an amount larger than the estimation:

  1. Even though you will not be charged anything extra, you still need to have that amount in your wallet (i.e., your wallet needs to hold an amount of gas limit x gas price ETH)
  2. Miners typically favor "highest price lowest limit", which means that the higher gas limit you use, the longer it will take for your transaction to get mined (executed)

There is definitely an advantage in specifying a gas limit slightly larger than the estimated gas cost, since the actual gas cost may change depending on the state of the chain (the values of all state variables involved) at the point in time when the transaction is executed.

Hence, using a gas limit slightly larger than the estimated gas cost reduces the probability of your transaction reverting on insufficient gas.

But for the reasons explained above, using a gas limit much larger than the estimated gas cost is generally not a very useful approach.

1 Like

I got it, in this case I guess I can deploy the contract by entering a value like 1320200 instead of 1120200. Thank you sir.