0
0
Blockchain / Solidityprogramming~10 mins

Checks-Effects-Interactions pattern 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 has enough balance before proceeding.

Blockchain / Solidity
require(balances[msg.sender] >= [1], "Insufficient balance");
Drag options to blanks, or click blank then click option'
AtotalSupply
Bmsg.value
Cbalance
Damount
Attempts:
3 left
💡 Hint
Common Mistakes
Using msg.value instead of amount, which is for payable functions.
Using balance or totalSupply which are not the correct variables here.
2fill in blank
medium

Complete the code to update the sender's balance after the check.

Blockchain / Solidity
balances[msg.sender] [1]= amount;
Drag options to blanks, or click blank then click option'
A-
B*
C+
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Adding the amount instead of subtracting.
Using multiplication or division operators incorrectly.
3fill in blank
hard

Fix the error in the interaction step to send Ether safely.

Blockchain / Solidity
(bool success, ) = payable(recipient).[1]{value: amount}("");
require(success, "Transfer failed.");
Drag options to blanks, or click blank then click option'
Asend
Bcall
Ctransfer
Ddelegatecall
Attempts:
3 left
💡 Hint
Common Mistakes
Using transfer which can fail with gas limits.
Using delegatecall which is for different purposes.
4fill in blank
hard

Fill both blanks to complete the Checks-Effects-Interactions pattern safely.

Blockchain / Solidity
require(balances[msg.sender] >= [1], "Not enough balance");
balances[msg.sender] [2]= amount;
Drag options to blanks, or click blank then click option'
Aamount
B+
C-
Dmsg.value
Attempts:
3 left
💡 Hint
Common Mistakes
Using msg.value instead of amount in the check.
Adding instead of subtracting the amount.
5fill in blank
hard

Fill all three blanks to complete the full Checks-Effects-Interactions pattern.

Blockchain / Solidity
require(balances[msg.sender] >= [1], "Insufficient funds");
balances[msg.sender] [2]= [1];
balances[recipient] [3]= [1];
Drag options to blanks, or click blank then click option'
Aamount
B-
C+
Dmsg.value
Attempts:
3 left
💡 Hint
Common Mistakes
Using msg.value instead of amount.
Mixing up addition and subtraction operators.