Inheritance
contract A {
function foo() public { // do something }
}
contract B is A {
function bar() public { // do something else }
}Import + Inherit
//SPDX-License-Identifier: MIT
pragma solidity 0.8.3;
contract Owned {
address owner;
constructor() {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner, "You are not the owner");
_;
}
}//SPDX-License-Identifier: MIT
pragma solidity 0.8.3;
import "./Owned.sol";
contract ModifierExample is Owned {
mapping(address => uint) public tokenBalance;
uint tokenPrice = 1 ether;
constructor() {
tokenBalance[owner] = 100;
}
function createNewToken() public onlyOwner {
tokenBalance[owner]++;
}
function burnToken() public onlyOwner {
tokenBalance[owner]--;
}
}Last updated