Function Modifiers

Learn how to use function modifiers in Solidity to eliminate repeated code in smart contracts.

A lot of code in our smart contracts is dedicated to checking pre-conditions, such as validating input arguments. In this lesson, we'll learn about function modifiers, a Solidity feature that enables us to implement and reuse pre- and post-condition implementation, or any code repeated across multiple functions.

Defining function modifiers

Using a function modifier, we can specify logic that should be executed before or after the body of a particular method. It's easier to explain how modifiers work through a specific example. Let’s say we have a smart contract, and this smart contract has an owner whose address is stored in a field of this contract:

Get hands-on with 1200+ tech skills courses.