Last active
August 2, 2023 12:56
-
-
Save CodeLeom/ec0ad7fa59dece3e3a99eaf728dbfd76 to your computer and use it in GitHub Desktop.
A smart contract that allows only the contract owner to perform an action
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: MIT | |
| 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"); | |
| owner = _newOwner; | |
| } | |
| function onlyOwnerCanCall() external onlyOwner { | |
| // code | |
| } | |
| function AnyOneCanCall() external { | |
| // code | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment