Failure mechanisms express different conditions and error shapes.
LET’S PICTURE IT
A form can fail a user requirement or reveal a violated internal rule; both stop the operation but carry different diagnostic meaning.
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.
Require checks a condition
A require condition can reject an operation when a required property is false. Its message or custom error syntax depends on the source and compiler features being used.
Revert signals an explicit failure
A revert can return an error encoding, including a custom error with typed arguments. State changes in the affected call are rolled back, while consumed work still has gas consequences.
Assert expresses an internal invariant
An assertion is intended for properties that should hold if the program’s logic is correct. A failed assertion has a panic form rather than being a substitute for every user-input check.
Decode, then investigate
The error name identifies a byte shape. The actual cause still needs the code path and state. A malicious contract can construct misleading error bytes, so decoding is not authentication.
Read the example
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract LearningExample {
function half(uint256 x) external pure returns (uint256) {
require(x % 2 == 0, "Use an even number");
return x / 2;
}
}
Odd input intentionally reverts with a readable Error(string).