Complete the code to make the contract able to receive Ether.
contract ReceiveEther {
receive() external payable [1] {
// Function to receive Ether
}
}The receive function must be marked payable to accept Ether.
Complete the fallback function to receive Ether when no other function matches.
contract ReceiveEther {
fallback() external [1] {
// fallback function
}
}The fallback function must be marked payable to accept Ether.
Fix the error in the receive function to correctly accept Ether.
contract ReceiveEther {
receive() external [1] {
// receive Ether
}
}The receive function must be external payable without view or pure modifiers.
Fill both blanks to create a receive function that accepts Ether and emits an event.
contract ReceiveEther {
event Received(address sender, uint amount);
receive() external [1] {
emit Received(msg.sender, msg.value[2]);
}
}The receive function must be payable and the event emits msg.value as is, so the plus sign is correct to complete the expression.
Fill both blanks to create a fallback function that accepts Ether, updates balance, and emits an event.
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]);
}
}The fallback function must be payable. Use += to add the received Ether to the sender's balance. The event emits the updated balance, so no extra operator is needed.