Web3 Dictionary Logo
Web3 Dictionary
Contribute

Categories

AllBlockchainDappsDAOsDeFiNFTsRegulationSecuritySmart ContractsTokenomicsWalletsWeb3 GamingOthers
  1. Web3 Dictionary
  2. Smart Contracts
  3. Modifier
Smart Contracts

Modifier

A reusable code segment that adds restrictions or requirements to function execution.

Last Updated

2026-03-19

Related Concepts

Smart ContractSolidityAccess ControlEthereum Virtual Machine
Web3-Explorer Logo

Scale Blockchain Infra

AD

Smart contracts, protocol integrations, and scalable architecture for high-performance Web3 products.

See Blockchain Services

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

  • onlyOwner restricts withdrawal functions to the contract deployer.
  • nonReentrant from OpenZeppelin blocks recursive calls.
  • whenNotPaused disables features during emergencies.

External References

  • Function Modifiers (Solidity Docs)
  • OpenZeppelin: Access Control