[Ethereum] Metamask shows “ALERT: Transaction Error. Exception thrown in contract code” but transaction succeeds without error

metamasksolidity

I've been testing my dapp and I noticed when I updated my contracts Metamask started to throw an error for one of the contracts we made a slight change to.

Metamask says the tx will fail and the contract will throw an error – but it doesn't. There is no error on the contract and everything works smoothly.

Metamask shows this: "ALERT: Transaction Error. Exception thrown in contract code."

A few times we've been able to remove the message by restarting our dev environment and metamask. But its not working this time.

Again – the submitted transaction is going through fine without any reverts or errors.

So… why is metamask showing this error message and how do we fix it?

edit: I've submitted multiple tx's when metamask shows this error and none of them have errored out. Basically just ignoring its message, but why is it happening.

Also testing the same contract with same input as our dapp uses in remix throws no errors. So…something is screwed up somewhere but not sure what

Best Answer

Looks like the gasEstimation for our contract was not able to be done due to a stack depth - although there were no errors for stack depth, when changing the contract around to identify what was causing metamask to throw the invalid error we did get a stack depth issue. So since this section of the contract that was very close to stack depth limitations, I'm assuming this was causing some of the gas estimation issues for metamask.

Switching require statements to reduce the stack depth removed the error from metamask. Even though no error was ever thrown when interacting with the contract, metamask was having issues estimating the gas.

Note this section of the contract was related to recovering signatures on chain - which has many variables by default, plus the ones required within the signed message.

Related Topic