Smart Contracts
Revert
Smart contract instruction that cancels transaction and reverts all state changes.
Last Updated
2026-03-19
Related Concepts
What is Revert?
A revert is a smart contract instruction that halts execution and rolls back all state changes from a transaction. It is the primary mechanism contracts use to enforce rules and reject invalid operations.
How does Revert work?
- A contract evaluates a condition via a
requirestatement during execution. - If the condition fails, a revert is triggered and all changes are rolled back.
- The user still pays gas for computation up to the point of failure.
- The transaction is recorded on-chain with a "Reverted" status and an error message.
Why does Revert matter?
Reverts enable atomic all-or-nothing transactions, ensuring a multi-step operation either completes fully or has zero effect. This is essential for safe financial interactions on-chain.
Key features of Revert
- Complete rollback of all state changes within the failed transaction
- Gas is still consumed up to the point of failure
- Error messages help developers and users diagnose issues
- Enables atomic multi-protocol transactions
Examples of Revert
Trying to swap more tokens than exist in a Uniswap pool triggers a revert. A mint contract reverts if the 10000 token supply cap has already been reached.
