0
0
Blockchain / Solidityprogramming~5 mins

Access control with OpenZeppelin in Blockchain / Solidity - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AAccessControl
BPausable
COwnable
DERC20
What does the onlyOwner modifier do?
AAllows only the contract owner to call the function
BAllows anyone to call the function
CPrevents the owner from calling the function
DAllows only addresses with a specific role
How do you create a new role in AccessControl?
ACall <code>transferOwnership</code>
BDefine a <code>bytes32</code> constant with <code>keccak256</code>
CUse <code>onlyOwner</code> modifier
DUse <code>approve</code> function
Which function assigns a role to an address in AccessControl?
AonlyOwner
BtransferOwnership
Capprove
DgrantRole
What is a key benefit of using AccessControl over Ownable?
ASupports multiple roles with different permissions
BOnly one owner can control the contract
CNo access restrictions
DAutomatically pauses the contract
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.