Orchestrate revert reason
Revert reason, if handled by the smart contract, is an information returned by nodes in case of error in the smart contracts execution.
Smart contract have to use the
require features to be able to return a revert reason.
The ERC20 token smart contract for instance can return a revert reason when not enough tokens are available at the source address when transferring tokens.
The message “ERC20: transfer amount exceeds allowance” is then returned to the user in the transaction receipt.
- The nodes registered in Orchestrate chain registry have to be able to return revert reason.
- The revert reason must be configured on nodes. For instance on Hyperledger Besu, the
--revert-reason-enabledoption must be set.
- The smart contract to which transaction are sent must implement a revert reason on failure.
Receive revert reason
To receive the revert reason when using Orchestrate, a consumer must be connected to Kafka using Orchestrate SDK.
You can find examples for using a consumer in the Orchestrate SDK documentation examples
Testing with ERC20 smart contract
You can receive a revert reason by calling an ERC20 contract transfer function by asking it to transfer more tokens than what’s available on the sender account.
When trying to transfer too many tokens using ERC20 contract with Orchestrate, you have to define a fixed amount of gas in your transaction. Otherwise Orchestrate will calculate it for you by dry running the transaction and will detect the issue before making the real transaction and you will not trigger the revert reason return.
During regular use, automatic gas setting is a very useful feature, but in this case you have to bypass it if you want to see the revert reason in action.
Revert reason display in transaction receipt
As indicated in the Solidity revert reason documentation, the revert reason is initially returned as an abi-encoded string by the node:
Raw revert reason
A not so easy to read encoded revert reason example.
Orchestrate helps by decoding the revert reason and displays the clear message in the output:
Decoded revert reason
revertReason property in the transaction receipt JSON output has the decoded
ERC20: transfer amount exceeds allowance string value instead of the encoded raw value.