Version 7.7.2
I've twice seen erc20 out of gas errors when transferring tokens on mainnet. The two tokens were USDC and WETH. What the failures had in common was that the gas estimation seemed to not take into account that the recipient had no prior balance, so the SSTORE cost 20000 instead of 5000. This can also happen if the recipient empties their balance before the transfer confirms but that wasn't true this case.
In both cases I was sending the entire token balance of my account.
I did not see a similar issue when I was transferring ETH to the WETH contract, which created WETH for an account that had none.
The workaround is to manually set the gas limit in Advanced.
I have now also reproduced this for GST2.
This issue seems to only affect transfers.
Sine we call eth_estimateGas from geth, and then add a 50% buffer, this seems like it is likely a bug in geth.
The most ideal reproduction would be to open the background network inspector, and copy as cURL the request to infura that is returning the insufficient gas estimate.
With that request, Infura and geth team members will be able to trace why the estimate is low.
@wjmelements Would you be willing to hop on a quick call to help us replicate this issue? We're having trouble recreating it. Do you have Telegram or some other medium I can use to contact you directly?
I can still 100% repro on 7.7.7.
Sine we call eth_estimateGas from geth, and then add a 50% buffer, this seems like it is likely a bug in geth.
I don't think metamask does that. Probably your estimate gas params are wrong.
Do you have Telegram or some other medium I can use to contact you directly?
I have the same username on most platforms
In both cases I was sending the entire token balance of my account.
Is this by using the Max Button?
I have found your bug, you are estimating gas with value=0 in the transfer

Value is determined in the data hex for token transfers.
Value is determined in the data hex for token transfers.
As seen in the data, it is 0
There are no subsequent calls to eth_estimateGas after the estimate with transfer of 0, so that is the issue. You have to re-estimate with the correct transfer value. A transfer of 0 will not change the 0-ness in the SSTORE when the recipient has no tokens.
Hmm I am fairly certain we update data on input change, otherwise we would see numerous other issues, but ill investigate that a little more. Can you clarify on what what method those params are for, I am guessing its for eth_estimateGas?
Can you clarify on what what method those params are for, I am guessing its for eth_estimateGas?
right
Here are repro steps, including a bug where you suggest a gas price that is 8x too high despite the "Slow" setting.






Also, note how the "Send Amount" shows 100% of my ETH instead of 100% of my MKR in the penultimate screenshot. I don't think that manifests in the TX but it's still fairly scary to think you might be sending all my ETH to the MKR token contract.
Hmm I am fairly certain we update data on input change
I have verified that you do when I type in the value, but you do not when the Max button is pressed instead.
Fixed by https://github.com/MetaMask/metamask-extension/pull/8176. Will get it out in the next release thanks for the report and investigation.
Most helpful comment
Fixed by https://github.com/MetaMask/metamask-extension/pull/8176. Will get it out in the next release thanks for the report and investigation.