I run a geth/parity nodes for broadcasting user's transactions to Ethereum blockchain. Some of contract functions provide reasons for revert (see examble below):
contract Example {
function test (uint i) {
require(i == 1, "ERROR_CODE")
}
}
As I understand it is not possible to get revert reason string with eth_getTransactionReceipt. However I still need to get revert reason for failed transactions.
How to get revert reason ("ERROR_CODE" in example above) for past failed transactions? (at least for transactions in last 20 blocks)
Best Answer
In solidity 0.4.22 the
require
andrevert
reason were added. As can be seen here, they are abi-encoded as if it were a call to a function "Error(string)".This blog post gives an example: an
eth_call
to a functionwith an invalid input argument (less than 5 in this example), will return
which is
So decoding the returned string will give you the revert reason.
With Web3j this could be done like: