xxxxxxxxxx
contract Owner {
modifier onlyOwner {
require(msg.sender == owner);
_;
}
modifier costs(uint price) {
if (msg.value >= price) {
_;
}
}
}
xxxxxxxxxx
//Modifiers are code that can be run before and / or after a function call.
//create modifier so the only person who can call the contract is the owner
modifier onlyOwner{
require(msg.sender == owner);
_;
}
//create modifier so that we only allocate funds if friend's grandpa deceased
modifier mustBeDeceased{
require(deceased == true);
_;
}
xxxxxxxxxx
modifier onlyOwner {
require(msg.sender == owner);
_;
//Use _ after the last require statement
}
xxxxxxxxxx
Solidity basic definition for beginners like me.
Modifiers are code that can be run before and / or after a function call.
Modifiers can be used to:
Restrict access
Validate inputs
Guard against reentrancy hack