Error Handling

The require node enforces rules in your contract. It takes a condition and a message. If the condition is true, execution continues normally. If the condition is false, the entire transaction is reverted and the caller sees your error message.

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 require node’s condition fails, everything the transaction did up to that point is undone. Balances, variable changes, events: all rolled back as if nothing happened. This is one of the most powerful safety features in Solidity.

Try It Yourself

Task 1 of 2 Write an Error Message

Add a message that appears when a condition fails.

1 Type a message
2 Done!
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