1

This seems like a trivial question, but I can't find an answer.

  • When you try to send a transaction with MetaMask, it calculates the amount of gas needed.

  • Most of the time if there's an error in your function (an unsatisfied revert test for example), it will notice it when calculating gas price and set it to 0. If you try to send the transaction anyway, you'll get the error. So it can predict some of the errors.

  • But sometimes, MetaMask calculates and finds an incorrect amount of gas. Most of the times if I set it higher manually I can send the transaction.

That means that it's an error that couldn't be foreseen, and the actual gas needed is higher than expected. How does that happen? Shouldn't MetaMask be able to see what is about to happen?

Why is there a difference between errors Metamask can predict and the others?

2

It's very difficult to sometimes estimate the amount of required gas. Some examples:

1) Arrays. If the contract for example iterates over all the values, Metamask doesn't know how many entries are in the array.

2) Calls to external contracts. They may do almost anything and consume all the gas given to them.

3) Different error situations (under what conditions does the contract throw, for example?)

  • And is there something you can do to make it easier for it to evaluate gas usage, so the user doesn't have to correct the gas limit every time? Especially when you're dealing with arrays (my function has no iterations, just simple assignments) – Teleporting Goat Apr 11 '18 at 10:19
  • I doubt you can give it 'hints'. Anyway, that's a bit out of scope for this forum, Metamask is third-party software. Maybe ask in their support forum or so? – Lauri Peltonen Apr 13 '18 at 5:13

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.