0Pricing
Blockchain Smart Contracts with Solidity · Lesson

Modifiers and the Checks-Effects-Interactions Pattern

Use function modifiers to enforce preconditions cleanly and apply the checks-effects-interactions pattern to write safer contracts.

What Are Modifiers?

A modifier is reusable code that runs before (or around) a function body. It is ideal for enforcing preconditions like access control without repeating the same checks everywhere.

Declaring a Modifier

The special _; placeholder marks where the function body executes. Code before it runs first; code after runs when the function returns.

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

All lessons in this course

  1. Inheritance and Interfaces
  2. Libraries and Abstract Contracts
  3. Error Handling with Revert/Require
  4. Modifiers and the Checks-Effects-Interactions Pattern
← Back to Blockchain Smart Contracts with Solidity