2.9. Modifiers#
Syntax#
Function Modifiers#
Function modifiers can be used to amend the semantics of functions in a declarative way:
contract MyContract {
modifier onlySeller() {
require(msg.sender == seller, "Only seller can call this.");
_; // Function body will be inserted here
}
function myFunction() public view onlySeller {
// Code here will be executed after `onlySeller` is executed.
}
}
Unlike functions, modifiers cannot be overloaded.
Note
This section is under construction. You are more than welcome to contribute suggestions to our GitHub repository.