0
0
Blockchain / Solidityprogramming~10 mins

Require, assert, and revert 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 check if the sender is the owner using require.

Blockchain / Solidity
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 '!=' instead of '==' causes the check to fail when sender is owner.
Using '<' or '>' operators for address comparison is invalid.
2fill in blank
medium

Complete the code to revert the transaction with a message if the balance is insufficient.

Blockchain / Solidity
if (balance < amount) [1]("Insufficient balance");
Drag options to blanks, or click blank then click option'
Arequire
Bthrow
Crevert
Dassert
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'throw' is deprecated in Solidity.
Using 'assert' is for internal errors, not user input checks.
3fill in blank
hard

Fix the error in the assert statement to check that totalSupply is not zero.

Blockchain / Solidity
assert([1] != 0);
Drag options to blanks, or click blank then click option'
Abalance
BtotalSupply
Cmsg.sender
Downer
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'msg.sender' or 'owner' in assert for this check is incorrect.
Checking 'balance' instead of 'totalSupply' does not verify total tokens.
4fill in blank
hard

Fill both blanks to create a require statement that checks if amount is greater than zero.

Blockchain / Solidity
require(amount [1] 0, "Amount must be positive");
assert(amount [2] 0);
Drag options to blanks, or click blank then click option'
A>
B<
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '==' will not correctly check for positive amounts.
Using '!=' does not ensure amount is positive.
5fill in blank
hard

Fill all three blanks to create a revert statement inside an if block that checks if sender is not owner.

Blockchain / Solidity
if (msg.sender [1] owner) {
    [2]("Unauthorized");
    [3];
}
Drag options to blanks, or click blank then click option'
A!=
Brevert
Creturn
Drequire
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'require' inside the if block is redundant here.
Not returning after revert can cause unexpected behavior.