0
0
Blockchain / Solidityprogramming~10 mins

Receiving Ether 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 make the contract able to receive Ether.

Blockchain / Solidity
contract ReceiveEther {
    receive() external payable [1] {
        // Function to receive Ether
    }
}
Drag options to blanks, or click blank then click option'
Apublic payable {}
B{}
Cexternal {}
Dpayable {}
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the payable keyword
Using public instead of external
Leaving the function body empty without braces
2fill in blank
medium

Complete the fallback function to receive Ether when no other function matches.

Blockchain / Solidity
contract ReceiveEther {
    fallback() external [1] {
        // fallback function
    }
}
Drag options to blanks, or click blank then click option'
Aview
Bpublic
Cpayable
Dpure
Attempts:
3 left
💡 Hint
Common Mistakes
Not marking fallback as payable
Using view or pure which disallow state changes
3fill in blank
hard

Fix the error in the receive function to correctly accept Ether.

Blockchain / Solidity
contract ReceiveEther {
    receive() external [1] {
        // receive Ether
    }
}
Drag options to blanks, or click blank then click option'
Apayable
Bpayable view
Cpure
Dview
Attempts:
3 left
💡 Hint
Common Mistakes
Adding view or pure modifiers
Omitting payable keyword
4fill in blank
hard

Fill both blanks to create a receive function that accepts Ether and emits an event.

Blockchain / Solidity
contract ReceiveEther {
    event Received(address sender, uint amount);

    receive() external [1] {
        emit Received(msg.sender, msg.value[2]);
    }
}
Drag options to blanks, or click blank then click option'
Apayable
Bpublic
C+
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using public instead of payable
Using multiplication instead of addition in event emit
5fill in blank
hard

Fill both blanks to create a fallback function that accepts Ether, updates balance, and emits an event.

Blockchain / Solidity
contract ReceiveEther {
    mapping(address => uint) public balances;
    event Received(address sender, uint amount);

    fallback() external [1] {
        balances[msg.sender] [2] msg.value;
        emit Received(msg.sender, balances[msg.sender]);
    }
}
Drag options to blanks, or click blank then click option'
Apayable
B+=
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Not marking fallback payable
Using = instead of += for balance update
Adding operators after balances[msg.sender] in event