Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to make the function accept Ether payments.
Blockchain / Solidity
function deposit() public [1] {
// Function body
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'view' or 'pure' which do not allow Ether transfers.
Forgetting to add 'payable' causes the function to reject Ether.
✗ Incorrect
The payable keyword allows the function to receive Ether.
2fill in blank
mediumComplete the code to access the amount of Ether sent to the function.
Blockchain / Solidity
function deposit() public payable {
uint amount = [1];
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'msg.sender' which is the sender's address, not the amount.
Using 'address(this).balance' which is the contract's total balance, not the sent amount.
✗ Incorrect
msg.value holds the amount of Ether (in wei) sent with the transaction.
3fill in blank
hardFix the error in the function declaration to allow receiving Ether.
Blockchain / Solidity
function receiveFunds() public [1] {
// Accept Ether
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'view' or 'pure' which prevent Ether transfers.
Omitting 'payable' causes the function to reject Ether.
✗ Incorrect
Only functions marked payable can receive Ether.
4fill in blank
hardFill both blanks to create a payable fallback function that accepts Ether.
Blockchain / Solidity
fallback() [1] [2] { // fallback logic }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Marking fallback as 'view' or 'pure' which is invalid.
Omitting 'payable' causes fallback to reject Ether.
✗ Incorrect
The fallback function must be external and payable to accept Ether.
5fill in blank
hardFill all three blanks to create a payable receive function that accepts Ether and updates balance.
Blockchain / Solidity
mapping(address => uint) public balances; receive() external [1] { balances[msg.sender] [2]= [3]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting 'payable' on the receive function.
Using '=' instead of '+=' which overwrites balance.
Using 'msg.sender' instead of 'msg.value' for amount.
✗ Incorrect
The receive function must be marked payable to accept Ether. The balance is updated by adding (+=) the amount sent (msg.value).