Exercise: Modifiers
Practice implementing function modifiers in Solidity.
We'll cover the following
In this short exercise, we'll practice using function modifiers in smart contracts and update the Ownable
smart contract in the process.
The onlyOwner
modifier
For this exercise, we'll implement a new modifier called onlyOwner
that'll enforce that a particular method is only called by the owner of the smart contract.
The starter code for this exercise can be found on this GitHub page.
To implement the new modifier, we need to make two changes that we’ve marked with TODO
comments:
Implement the new
onlyOwner
modifier that enforces that a method can only be called by the contract’s owner.Apply the new modifier on the
transferOwnership
method.
Here are the changes we need to make:
Get hands-on with 1200+ tech skills courses.