Modifier + Inheritance +Ownable
modifier onlyOwner() {
require(msg.sender == owner, "Not owner");
// Underscore is a special character only used inside
// a function modifier and it tells Solidity to
// execute the rest of the code.
_;
}// This modifier prevents a function from being called while
// it is still executing
modifier noReentrancy() {
require(!locked, "No reentrancy");
locked = true;
_; // function executes
locked = false;
}//SPDX-License-Identifier: MIT
pragma solidity 0.8.3;
contract ModifierExample {
mapping(address => uint) public tokenBalance;
address owner;
uint tokenPrice = 1 ether;
constructor() {
owner = msg.sender;
tokenBalance[owner] = 100;
}
function createNewToken() public {
require(msg.sender == owner, "You are not the owner");
tokenBalance[owner]++;
}
function burnToken() public {
require(msg.sender == owner, "You are not the owner");
tokenBalance[owner]--;
}
}Inheritance
Last updated