Skip to content

Instantly share code, notes, and snippets.

@elijahboston
Created October 19, 2023 16:57
Show Gist options
  • Save elijahboston/824d205378f5d991ad2397cd10af01a6 to your computer and use it in GitHub Desktop.
Save elijahboston/824d205378f5d991ad2397cd10af01a6 to your computer and use it in GitHub Desktop.
StorageWithOwnership.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract StorageWithOwnership {
uint256 number;
address public owner;
constructor() {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner, "Not the contract owner");
_;
}
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0), "New owner is the zero address");
owner = newOwner;
}
function store(uint256 num) public onlyOwner {
number = num;
}
function retrieve() public view returns (uint256) {
return number;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment