address owner;
bool public paused;
constructor() public {
owner = msg.sender;
}
function setPaused(bool _paused) public {
require(msg.sender == owner, "you are not authorized for this action");
pause = _paused;
} |
First on DEPLOYMENT you want to be sure that the owner is the only who interacts with the contract for concrete actions:
- Address of deployer is the owner
- constructor(): initializes contract class
- setPaused(): pause control of contract
- require(): basic owner authorization
function withdrawAll(address payable _to) public {
require(msg.sender == owner, "you are not authorized for this action");
require(!paused, "Contract is paused!");
_to.transfer(address(this).balance);
} |
Second during the LIFECYCLE, you can make any actions on contract balance:
- require(sender): checks auth
- require(paused): checks if contract is suspended
- address(this): gets address of this contract
function destroy (address payable _to) public {
require(msg.sender == owner, "you are not authorized for this action");
selfdestruct(_to);
} |
Last, you can disable a contract by selfdestructing and sending balance to any address the owner wants.