Skip to content

Instantly share code, notes, and snippets.

@shubham-kanodia
Created October 30, 2022 06:07
Show Gist options
  • Save shubham-kanodia/98f5489d65805dd6420b96e0d5bc182f to your computer and use it in GitHub Desktop.
Save shubham-kanodia/98f5489d65805dd6420b96e0d5bc182f to your computer and use it in GitHub Desktop.
Trivia #27
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
contract A {
error InvalidOwnerOrNewAddress(address newOwner);
address public owner;
constructor() {
owner = msg.sender;
}
function changeOwner(address _newOwner) public {
// Only an owner can set a new owner
bool isOwner = (owner == msg.sender);
bool isNewOwnerValid = (_newOwner != address(0));
if (isOwner && isNewOwnerValid) {
owner = _newOwner;
}
else {
revert InvalidOwnerOrNewAddress(_newOwner);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment