0
0
Blockchain / Solidityprogramming~10 mins

Access control with OpenZeppelin in Blockchain / Solidity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the AccessControl contract from OpenZeppelin.

Blockchain / Solidity
import "@openzeppelin/contracts/access/[1].sol";
Drag options to blanks, or click blank then click option'
AAccessControl
BERC20
CPausable
DOwnable
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Ownable instead of AccessControl.
Using ERC20 which is for tokens.
Forgetting the .sol extension.
2fill in blank
medium

Complete the code to declare a role identifier for ADMIN_ROLE.

Blockchain / Solidity
bytes32 public constant ADMIN_ROLE = [1]("ADMIN_ROLE");
Drag options to blanks, or click blank then click option'
Ahash256
Bsha256
Ckeccak256
DencodePacked
Attempts:
3 left
💡 Hint
Common Mistakes
Using sha256 which is different from keccak256.
Using hash256 which does not exist.
Using encodePacked which returns bytes, not bytes32.
3fill in blank
hard

Fix the error in the constructor to grant ADMIN_ROLE to the deployer.

Blockchain / Solidity
constructor() {
    _setupRole([1], msg.sender);
}
Drag options to blanks, or click blank then click option'
ADEFAULT_ADMIN_ROLE
BADMIN_ROLE
COWNER_ROLE
DMINTER_ROLE
Attempts:
3 left
💡 Hint
Common Mistakes
Using DEFAULT_ADMIN_ROLE which is different.
Using OWNER_ROLE which is not declared.
Using MINTER_ROLE which is unrelated.
4fill in blank
hard

Fill both blanks to restrict the function to only ADMIN_ROLE holders.

Blockchain / Solidity
function restrictedAction() public [1](ADMIN_ROLE) [2] {
    // action code
}
Drag options to blanks, or click blank then click option'
AonlyRole
Bpublic
Cexternal
Dview
Attempts:
3 left
💡 Hint
Common Mistakes
Using external visibility which is valid but not the intended answer here.
Using view which restricts state changes.
Omitting the onlyRole modifier.
5fill in blank
hard

Fill all three blanks to create a new role and grant it to an address.

Blockchain / Solidity
bytes32 public constant [1] = keccak256("[1]_ROLE");

function grantNewRole(address user) public [2](ADMIN_ROLE) {
    _grantRole([1], user);
}
Drag options to blanks, or click blank then click option'
AMINTER
BonlyRole
DPAUSER
Attempts:
3 left
💡 Hint
Common Mistakes
Using PAUSER instead of MINTER.
Omitting the onlyRole modifier.
Mismatching role names.