Skip to content

Instantly share code, notes, and snippets.

@KevinSmall
Last active August 21, 2019 08:05
Show Gist options
  • Save KevinSmall/c158bf465e9a0d38a78cde76c4da3f5f to your computer and use it in GitHub Desktop.
Save KevinSmall/c158bf465e9a0d38a78cde76c4da3f5f to your computer and use it in GitHub Desktop.
Getting Revert Reasons From Solidity

See also summary on issue with calls here: https://forum.openzeppelin.com/t/require-in-view-pure-functions-dont-revert-on-public-networks/1211

Getting Revert Reasons from the Solidity Require Statement

There is a test contract 0x6491eb4fb1269c7587451cf0102437a685897b78 you can interact with on etherscan Rinkeby. It has functions getWithCheck and setWithCheck to get and set a value. If you pass a parameter >=0 the function will be ok, if you pass a parameter <0 the function fails at the require statement.

1) Calls

For 'getWithCheck', the require statement triggers a Geth bug and you get back the mysterious value: 3963877391197344453575983046348115674221700746820753546331534351508065746944. This value in hex becomes 0x08c379a0 which is the function selector for Error(string), as described in the solidity docs. However that still doesn't show the revert reason.

So no revert reason there for calls. However, when using the Remix JavaScript VM the correct message does display.

2) Transactions

In Remix and Nethereum you get exception "gas required exceeds allowance... or always failing transaction". This gives caller a chance to not waste any gas. Similarly, on etherscan dapp screen we get "ALERT: Transaction Error. Exception thrown in contract code." without any message.

If you do send the transaction anyway, then there is nothing in the transaction logs that tells you the error message.

So no revert reason there for transactions, before or after sending them. However when using the Remix JavaScript VM the correct message does display in the console (nothing in the tx receipt that I can see).

The solidity docs suggest that the revert message should be available, see the end of this section. A comment on the Ethereum github says that the revert reason is visible only to callers that are other contracts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment