Typed failures can encode useful context compactly.
LET’S PICTURE IT
A rejection form can identify a specific rule and include the values relevant to the failed request.
SEE IT FOR YOURSELF
Follow a revert and decode its error dataStep 1 / 4
This fictional call requests a transfer of one hundred raw units while the relevant balance is forty.
This fictional call requests a transfer of one hundred raw units while the relevant balance is forty.The contract rejects this request. State changes in the reverted call are rolled back, while work already consumed can still cost gas.A common Error(string) begins with selector 08c379a0. This example then encodes the message Not enough tokens.A decoder can recognize the supplied error shape. Identifying the true cause and source still needs the call context, code and state.
Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.
Declare a schema for failure
A custom error has a name and typed parameters. Its ABI representation uses a four-byte selector followed by encoded arguments, resembling function-call framing.
Use it on the actual path
The declaration alone does not enforce a condition. Code must check the condition and revert with the error when appropriate.
Decode with the correct declaration
A decoder needs the error interface to interpret custom arguments. The selector is short and can collide; bytes do not provide a globally authenticated error identity.
Investigate beyond the name
An Unauthorized error can be useful evidence, while the caller context and ownership state explain why the check failed. The local decoder does not fetch those facts.
Read the example
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract LearningExample {
error TooLarge(uint256 supplied);
function bounded(uint256 x) external pure returns (uint256) {
if (x > 100) revert TooLarge(x);
return x;
}
}
Try the same error declaration in the revert decoder with encoded sample data.