Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Ownable instead of AccessControl.
Using ERC20 which is for tokens.
Forgetting the .sol extension.
✗ Incorrect
The AccessControl contract is imported from OpenZeppelin to manage roles and permissions.
2fill in blank
mediumComplete 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'
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.
✗ Incorrect
keccak256 is used to create a unique bytes32 identifier for roles.
3fill in blank
hardFix 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'
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.
✗ Incorrect
The ADMIN_ROLE constant should be granted to the deployer in the constructor.
4fill in blank
hardFill 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'
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.
✗ Incorrect
The onlyRole modifier restricts access, and the function visibility is public.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using PAUSER instead of MINTER.
Omitting the onlyRole modifier.
Mismatching role names.
✗ Incorrect
The MINTER role is declared and granted using onlyRole modifier to restrict access.