Skip to content

Instantly share code, notes, and snippets.

@CodeLeom
Last active August 2, 2023 12:56
Show Gist options
  • Select an option

  • Save CodeLeom/ec0ad7fa59dece3e3a99eaf728dbfd76 to your computer and use it in GitHub Desktop.

Select an option

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
// 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