Loading...
'Who can call this?' is a question every production contract must answer. Ownable is the simplest answer.
solidityimport "@openzeppelin/contracts/access/Ownable.sol"; contract Vault is Ownable { constructor() Ownable(msg.sender) {} function withdrawAll(address payable to) public onlyOwner { to.transfer(address(this).balance); } }
owner() — public view of the current owneronlyOwner modifier — reverts if msg.sender != ownertransferOwnership(address) — owner can hand over controlrenounceOwnership() — owner can burn ownership (contract becomes uncontrollable)Ownable gives ONE role. Real systems have MULTIPLE roles (minter, pauser, treasurer). Use AccessControl for role-based permissions — we'll cover that next.
Write a Treasury contract that: 1. Inherits Ownable 2. Holds ETH 3. Has a sendTo function only the owner can call, which sends a given amount to an address