Last active
June 27, 2022 12:35
-
-
Save alexpanasUCLA/c3748ad21896ae9b6a5235b2fd98074d to your computer and use it in GitHub Desktop.
Ownable contract example.
This file contains 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: GPL-3.0 | |
pragma solidity >=0.7.0; | |
contract Ownable | |
{ | |
// Variable that maintains | |
// owner address | |
address private _owner; | |
// Sets the original owner of | |
// contract when it is deployed | |
constructor() | |
{ | |
_owner = msg.sender; | |
} | |
// Publicly exposes who is the | |
// owner of this contract | |
function owner() public view returns(address) | |
{ | |
return _owner; | |
} | |
// onlyOwner modifier that validates only | |
// if caller of function is contract owner, | |
// otherwise not | |
modifier onlyOwner() | |
{ | |
require(isOwner(), | |
"Function accessible only by the owner !!"); | |
_; | |
} | |
// function for owners to verify their ownership. | |
// Returns true for owners otherwise false | |
function isOwner() public view returns(bool) | |
{ | |
return msg.sender == _owner; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment