Created
March 24, 2020 14:32
-
-
Save alexroan/c4ae5cedb79f22e2dd9559f1d0b28186 to your computer and use it in GitHub Desktop.
examples/solidity-custom-modifiers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >=0.5.0; | |
contract CustomModifiers { | |
// State variable | |
address private owner; | |
// Custom modifier requiring that the sender of the transaction is the owner | |
// otherwise revert the transaction | |
modifier onlyOwner { | |
require(msg.sender == owner, "Only owner can call this function."); | |
_; | |
} | |
// Constructor takes an address and stores it in the owner variable | |
constructor(address _owner) public { | |
owner = _owner; | |
} | |
// someFunction() uses the onlyOwner modifier to make use of our | |
// custom definition on line 10 | |
function someFunction() external onlyOwner { | |
... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment