0
0
Blockchain / Solidityprogramming~10 mins

Function modifiers 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 declare a function modifier named onlyOwner.

Blockchain / Solidity
modifier [1]() {
    _;
}
Drag options to blanks, or click blank then click option'
AcheckOwner
BownerOnly
ConlyOwner
DownerModifier
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different modifier name than declared.
Forgetting the modifier keyword.
2fill in blank
medium

Complete the code to require that the caller is the owner inside the onlyOwner modifier.

Blockchain / Solidity
modifier onlyOwner() {
    require(msg.sender [1] owner, "Not owner");
    _;
}
Drag options to blanks, or click blank then click option'
A!=
B>
C<
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using != which would reject the owner.
Using comparison operators like < or > which are invalid for addresses.
3fill in blank
hard

Fix the error in the modifier usage in the function declaration.

Blockchain / Solidity
function withdraw() public [1] {
    // withdraw logic
}
Drag options to blanks, or click blank then click option'
AonlyOwner
BonlyOwner()
ConlyOwner{}
DonlyOwner;
Attempts:
3 left
💡 Hint
Common Mistakes
Adding parentheses after the modifier name when it has no parameters.
Using braces or semicolons after the modifier name.
4fill in blank
hard

Fill both blanks to create a modifier that checks if the caller is the owner and then executes the function.

Blockchain / Solidity
modifier [1]() {
    require(msg.sender [2] owner, "Caller is not owner");
    _;
}
Drag options to blanks, or click blank then click option'
AonlyOwner
B==
C!=
DownerOnly
Attempts:
3 left
💡 Hint
Common Mistakes
Using != which rejects the owner.
Using a wrong modifier name.
5fill in blank
hard

Fill all three blanks to create a modifier named onlyOwner that requires the caller to be the owner and then executes the function.

Blockchain / Solidity
modifier [1]() {
    require(msg.sender [2] owner, "Not owner");
    [3];
}
Drag options to blanks, or click blank then click option'
AownerOnly
B==
C_
DonlyOwner
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong modifier names.
Forgetting the _; statement.