Skip to main content

Posts

Showing posts with the label Ownable Contracts

LEARN SOLIDITY LESSON 10: Function Modifier Solidity. OpenZeppelin's Ownable contract

LEARN SOLIDITY LESSON Function Modifier Solidity. OpenZeppelin's Ownable contract Function Modifier Solidity A function modifier looks just like a function, but uses the keyword modifier instead of the keyword function. And it can't be called directly like a function can — instead we can attach the modifier's name at the end of a function definition to change that function's behavior. modifier onlyOwner() { require(isOwner()); _; } function renounceOwnership() public onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } //Step code run when call: renounceOwnership 1. require(isOwner()); 2. _; 3. emit OwnershipTransferred(_owner, address(0)); 4. _owner = address(0); OpenZeppelin's Ownable contract Below is the Ownable contract taken from the OpenZeppelin Solidity library. OpenZeppelin is a library of secure and community-vetted smart contracts that you can use in your own DApps.  /** * @title Ownable * @dev...