Describe the bug
When sending to a contract with a fallback payable function, Metamask incorrectly estimates gas if destination address is entered first, but estimates correctly if amount is entered before address.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Metamask should set the gas limit correctly regardless of whether the user enters the address or amount first.
Browser details (please complete the following information):
Additional context
Here's the contract source for reference https://github.com/deconet/DeconetPaymentsSplitting/blob/master/contracts/DeconetPaymentsSplitting.sol
Is there any technical documentation (or good place in a source file) for looking up how Metamask currently determines the gas limit?
I've repeatedly observed seemingly random behavior, with Metamask setting the gas limit sometimes too low, sometimes too high, while at the same time I had reliable estimates when using web3.eth.estimateGas() and web3.eth.Contract.methods.estimateGas() (e.g. in a truffle console) for similar interactions.
How does Metamask determine the pre-set value for gas limit and what triggers this calculation?
May it be that there's possible race conditions, leading to different outcomes for the same user input?
In my case, the behavior described here (estimate correct if amount set first) would already be an improvement. Instead unfortunately, regardless of the order of data entry, the estimate may be good or bad. As if there were possible race conditions.
I'm using the latest Metamask with Chromium on Linux, but have seen similar issues on other browsers and operating systems.
I already looked into the option of using EIP-861 URLs / QR-codes in order to allow non-technical people to avoid gas-related issues when using Metamask for interacting with contracts (at the moment just plain ETH transfers, which however trigger logic of fallback functions), but that seems to not be supported either (Metamask reads the receiver address, but ignores the encoded gas settings).
I confirm I'm having the same issue as @glitch003. To add up to the information provided by him, the problem seems to happen when the recipient address is a contract. Maybe @danfinlay can help us with this.
Is there any technical documentation (or good place in a source file) for looking up how Metamask currently determines the gas limit?
The method estimateTxGas here: https://github.com/MetaMask/metamask-extension/blob/develop/app/scripts/controllers/transactions/tx-gas-utils.js#L57-L104
Most helpful comment
I confirm I'm having the same issue as @glitch003. To add up to the information provided by him, the problem seems to happen when the recipient address is a contract. Maybe @danfinlay can help us with this.