Search⌘ K
AI Features

Function Modifiers

Explore how to declare and apply function modifiers in Solidity that modify function execution based on conditions like ownership. Understand combining modifiers, argument handling, and testing access control for secure smart contract functionality.

Modifiers can be used to change the behavior of functions in a declarative way. They can be considered as helper code that changes the behavior of functions. We can have modifiers that check access or the existence of certain data before the main function code is run.

Declaring modifiers

To declare modifiers, we use the modifier keyword, followed by the name and then the body of the modifier. The modifier body must contain at least one _; line. This line specifies the point where we wish to inject the body of the function called with the modifier.

Note: Modifiers do not return any value.

When using a defined modifier in a function, we ...