Smart Contracts
Modifier
A reusable code segment that adds restrictions or requirements to function execution.
Last Updated
2026-03-19
Related Concepts
What is Modifier?
A modifier is reusable Solidity code attached to a function that checks conditions before allowing the function to execute. If conditions fail, the transaction reverts.
How does Modifier work?
The modifier runs its check logic first. The _ symbol marks where the function body executes.
If a require inside the modifier fails, execution stops and gas is refunded for unused computation.
Why does Modifier matter?
Modifiers centralize security checks, reduce code duplication, and make access control visible at the function signature reducing audit complexity and developer error.
Key features of Modifier
- Reusable across multiple functions
- Auto-reverts on failed conditions
- Makes security requirements explicit
- Can accept parameters
Examples of Modifier
onlyOwnerrestricts withdrawal functions to the contract deployer.nonReentrantfrom OpenZeppelin blocks recursive calls.whenNotPauseddisables features during emergencies.
