Skip to content

Instantly share code, notes, and snippets.

@alexroan
Created March 24, 2020 14:32
Show Gist options
  • Save alexroan/c4ae5cedb79f22e2dd9559f1d0b28186 to your computer and use it in GitHub Desktop.
Save alexroan/c4ae5cedb79f22e2dd9559f1d0b28186 to your computer and use it in GitHub Desktop.
examples/solidity-custom-modifiers
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