Solidity0.8.0-Ownable合约
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.7; contract Ownable { address public owner; constructor() { owner = msg.sender; } modifier onlyOwner() { require(msg.sender == owner, "not owner"); _; //函数中其他的代码在 } ////函数中其他的代码在下划线这个位置运行 function setOwner(address _newOwner) external onlyOwner { //切换合约管理员 require(_newOwner != address(0), "invalid address"); //确认是否是0地址 owner = _newOwner; } function onlyOwnerCanCallThisFunc() external onlyOwner { //code } function anyOneCanCall() external { //code } }