Error Handling
The
Fields
- Condition: the rule that must be true (often wired from a
compare node) - Message: the error text shown when the condition fails
How It Works
When a
Try It Yourself
Task 1 of 2 Write an Error Message
Add a message that appears when a condition fails.
Type Not enough funds in the Message field.
Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.
Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.
Common Patterns
- Balance checks: compare a user’s balance against the withdrawal amount before allowing a transfer
- Ownership guards: compare the sender’s address to the stored owner, blocking unauthorized callers
- Input validation: check that a value is within an acceptable range before storing it
What You Learned
require nodes enforce rules by testing a condition- If the condition is false, the transaction reverts with your error message
- Everything the transaction did is undone, protecting the contract’s state
How hard was this?
Easy Hard