Reading a Revert Reason Without an Explorer
Bottom line: eth_call against the failing state returns the revert data hex. Decode it — standard Error(string) is selector 0x08c379a0, Panic(uint256) is 0x4e487b71 — instead of guessing from a truncated UI toast.
What a revert contains
A revert carries an ABI-encoded reason. Explored UIs truncate it; the raw call does not. Two standard shapes and one custom:
| Selector | Meaning | Decode as |
|---|---|---|
0x08c379a0 |
Error(string) |
string, human message |
0x4e487b71 |
Panic(uint256) |
code (0x11 overflow, 0x12 div-by-zero) |
| other | custom error | ABI from the contract’s source |
Reproduce with eth_call
1 | cast call $CONTRACT "swap(address,uint256)" $TO 1e18 \ |
Replay at the failing block if the state has moved: --block <n>. A revert that disappears on the latest block was a state race, not a code bug.
Decode
1 | from eth_abi import decode |
Custom errors need the ABI: cast 4byte <selector> when the source is verified, or the contract’s own ABI file.
The common causes, ranked
TRANSFER_FROM_FAILED— allowance or balance, nearly always allowanceINSUFFICIENT_OUTPUT_AMOUNT— slippage too tight for current pool stateEXPIRED— deadline passed, usually a clock or a slow signing step- Panic 0x11 — arithmetic overflow in a fee calculation with a bad input
Each maps to a different fix. Without the string, all four look like “swap failed”.
Simulating before sending
eth_call with --from your address and the exact calldata predicts the revert for free. Wire it into the send path: simulate, decode, abort with the reason. That converts a 40k-gas failed transaction into a local error.
What not to do
Raising slippage until the revert disappears hides a price problem that will cost more than the failed transaction. Decode first, widen second, and widen by 50 bps at a time.
Operating notes
Always replay at the exact failing block number, never at latest. A revert that vanishes on the current block was a state race; a revert that reproduces means the code or the input is wrong. Those two need opposite fixes and the block pin is what separates them.
Capture four things on every failure, in one line, before decoding: block number, sender, calldata selector, and the raw revert data. Without the sender the simulation is a different call — msg.sender changes allowances and access checks.
Decoding custom errors
cast 4byte <selector> resolves only if the selector is public. For a private contract, take the ABI from the verified source or from your build output, then decode with eth_abi using that ABI’s error types. An unresolvable selector still narrows the search: check the contract’s error definitions for an exact 4-byte match.
Simulation as a gate
Run eth_call with the real sender and real calldata in the send path. On revert, decode and abort locally. This converts a failed on-chain transaction — 40,000 gas plus a nonce — into a free local error, and it turns “swap failed” into the reason string that says which of the four common causes applied.
What to keep in the logs
Block, selector, decoded reason, and the fee ratio at failure. The decoded reason alone is useless for a trend; with the block you can tell whether a contract change preceded the spike.
FAQ
What does the 0x08c379a0 selector mean in revert data?
It marks the standard Error(string) revert shape, carrying a human-readable message. Decode the bytes after the selector as a string to get the reason. This is the most common revert format you’ll encounter.
How do I reproduce a revert with eth_call?
Call the contract with the same function signature and arguments, passing --from your address and the exact calldata. Add --block <n> to replay at the failing block if state has moved. A revert that disappears on the latest block was a state race, not a code bug.
What does Panic code 0x11 mean?
Panic 0x11 indicates an arithmetic overflow. It appears in the Panic(uint256) shape under selector 0x4e487b71. In practice it often shows up in a fee calculation with a bad input. Decode the panic code to confirm before changing anything.
Why should I replay at the failing block instead of latest?
A revert that vanishes on the current block was a state race; one that reproduces means the code or input is wrong. Those two need opposite fixes, and the block pin is what separates them. Always replay at the exact failing block number.
How do I decode a custom error without a verified source?
Use cast 4byte <selector> when the selector is public. For a private contract, take the ABI from the verified source or your build output and decode with eth_abi using that ABI’s error types. An unresolvable selector still narrows the search to an exact 4-byte match in the contract’s error definitions.











