Skip to content

Instantly share code, notes, and snippets.

@TehilaFavourite
Created June 29, 2023 23:57
Show Gist options
  • Save TehilaFavourite/178535d2ceb93dba13f9b4a53903e83b to your computer and use it in GitHub Desktop.
Save TehilaFavourite/178535d2ceb93dba13f9b4a53903e83b to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
contract OwnedContract {
address public owner;
constructor() {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner, "Only the contract owner can call this function.");
_;
}
function transferOwnership(address newOwner) external onlyOwner {
require(newOwner != address(0), "Invalid address.");
owner = newOwner;
}
// Example function only callable by the contract owner
function doSomething() external onlyOwner {
// Perform some privileged operation
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment