Solidity theorytheory 0/50 · 0%
Functions · easy

13. Modifiers

Reusable pre- and post-checks.

A modifier wraps a function body, which runs where `_;` appears. They are ideal for access control and state guards, and keep the check in one auditable place.

modifier onlyOwner() {
    require(msg.sender == owner, "not owner");
    _;
}

function setRate(uint256 r) external onlyOwner { rate = r; }

Keep modifiers small: complex logic hidden in a modifier is easy to misread during review.

Check your understanding

  1. 1. What does `_;` mean in a modifier?

  2. 2. What are modifiers most used for?

  3. 3. Can several modifiers apply to one function?