In this track: Read logs and failures
advanced · 4 MIN READ

Decode a custom Solidity error

The error declaration supplies names and types for its payload.

LET’S PICTURE IT

A specialized failure form can carry two exact quantities rather than a sentence.

SEE IT FOR YOURSELF
Follow a revert and decode its error dataStep 1 / 4
Follow a revert and decode its error dataRequested actionTransfer 100 raw unitsExample inputsAvailable balance40 raw unitsCheck the ruleA deliberately failing local scenario, not a live transactionCondition fails100 > 40Request rejectedRollbackNo successful transferConsumed gas still mattersTop-level failure and a caught nested failure have different contextsError selector0x08c379a04 bytesMessage tailNot enough tokensDynamic string encodingCustom errors and Panic use different selectors and schemasDecoded messageNot enough tokensA diagnostic clueFurther evidenceCaller and code pathRelevant stateError bytes can be constructed by code; decoding is not authentication

This fictional call requests a transfer of one hundred raw units while the relevant balance is forty.

Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.

Start from the declaration

InsufficientBalance(uint256,uint256) has a selector derived from its canonical error signature. Parameter names help explain the values but do not change that selector.

Decode the typed arguments

For available three and requested five, the selector is followed by two integer words. This error has static arguments and needs no dynamic tail.

Keep the ABI available

Raw error bytes do not include the full declaration. A decoder needs a known schema or a candidate declaration and must account for selector collisions.

Interpret without trusting blindly

Decoded field names come from the supplied ABI, and any contract can construct matching bytes. Check the source and call frame before treating those values as verified balances.

Inspect the example

0xcf47918100000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000005

Use error InsufficientBalance(uint256 available, uint256 requested) in the custom decoder.

TURN UNDERSTANDING INTO PRACTICEOpen the Revert decoder →
QUICK CHECK · NO PRESSURE

Are custom error parameter names embedded in the bytes?

Your progress stays in this browser.
Keep exploring the original referenceSolidity documentation ↗

Original explanations by EtherTools. Examples are educational and source-linked; this site is independent of the Ethereum Foundation. Our approach.