Recall & Review
beginner
What is the purpose of access control in smart contracts?
Access control restricts who can call certain functions in a smart contract to protect sensitive operations and prevent unauthorized actions.
Click to reveal answer
beginner
What is OpenZeppelin's
Ownable contract used for?Ownable provides a simple access control mechanism where there is an owner account that can be granted exclusive access to specific functions.Click to reveal answer
beginner
How do you restrict a function to be called only by the owner using OpenZeppelin?
Use the
onlyOwner modifier provided by the Ownable contract. It checks if the caller is the owner before running the function.Click to reveal answer
intermediate
What is the difference between
Ownable and AccessControl in OpenZeppelin?Ownable manages a single owner with exclusive rights. AccessControl allows multiple roles with different permissions, offering more flexible access management.Click to reveal answer
intermediate
How do you define a new role using OpenZeppelin's
AccessControl?Define a
bytes32 constant for the role, e.g., bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");, then use _setupRole or grantRole to assign it.Click to reveal answer
Which OpenZeppelin contract provides a simple owner-based access control?
✗ Incorrect
Ownable is designed for single-owner access control.What does the
onlyOwner modifier do?✗ Incorrect
onlyOwner restricts function calls to the owner.How do you create a new role in
AccessControl?✗ Incorrect
Roles are defined as
bytes32 constants using keccak256.Which function assigns a role to an address in
AccessControl?✗ Incorrect
grantRole assigns roles to addresses.What is a key benefit of using
AccessControl over Ownable?✗ Incorrect
AccessControl supports multiple roles, unlike Ownable.Explain how to use OpenZeppelin's
Ownable contract to restrict a function to the contract owner.Think about how the contract knows who the owner is and how it checks the caller.
You got /3 concepts.
Describe the steps to create and assign a new role using OpenZeppelin's
AccessControl.Roles are like keys that let addresses do certain things.
You got /3 concepts.