Decode a Solidity custom error returned by a failed call

A failed simulation may provide structured bytes even when the RPC message says only execution reverted. Match the bytes to the error declarations in the relevant ABI.

Split selector and arguments

Suppose the ABI declares error InsufficientBalance(uint256 available,uint256 required). Take four bytes of Keccak-256 of the canonical signature shown below. Compare them with the first four revert bytes and decode the following two words as unsigned integers.

InsufficientBalance(uint256,uint256)

If the words decode to 3 and 5, display those values as available and required. Apply token decimals only when the contract’s semantics identify the unit. Preserve the raw revert payload for later inspection.

Treat the decoder as an interpretation

Revert data can bubble through several calls and arbitrary code can fabricate an error with the same signature. A match explains the encoding. A call trace can identify the failing frame when the originating contract matters. docs.soliditylang.org Solidity ABI