interesting, i guess this solution is to make sure that when calling this function, there is no waste of gas to keeping the same owner address. only when changing a different owner/address;
The setOwner function is marked with the onlyOwner modifier, which means that it can only be called by the current owner of the contract. It takes an address as an argument, which is the new owner that the current owner wants to set. It also has a require statement that checks that the new ownerâs address is not the zero address which is an invalid address. If the requirement is met, the owner variable is updated with the new ownerâs address.
pragma solidity 0.5.1;
contract Ownable {
address public owner;
constructor() public {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
function setOwner(address newOwner) public onlyOwner {
require(newOwner != address(0));
owner = newOwner;
}
}
1 Like