0
0
Blockchain / Solidityprogramming~5 mins

Receive and fallback functions in Blockchain / Solidity - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the receive function in a smart contract?
The receive function is a special function in Solidity that is executed when the contract receives plain Ether without any data. It allows the contract to accept Ether transfers.
Click to reveal answer
beginner
When is the fallback function triggered in a smart contract?
The fallback function is called when a contract receives a call with data that does not match any function signature or when Ether is sent but no receive function is defined or if the receive function is not payable.
Click to reveal answer
intermediate
Can a contract have both receive and fallback functions? What happens if both exist?
Yes, a contract can have both. The receive function handles plain Ether transfers with empty calldata, while the fallback function handles calls with data or Ether transfers when receive is not present or not payable.
Click to reveal answer
beginner
What visibility and modifiers must the receive function have?
The receive function must be declared as external and payable to accept Ether transfers.
Click to reveal answer
beginner
What happens if a contract does not have a receive or fallback function and it receives Ether?
The transaction will fail and revert because the contract cannot accept Ether without a receive or fallback function marked payable.
Click to reveal answer
Which function is called when a contract receives Ether with empty calldata?
Aconstructor()
Bfallback()
Cpayable()
Dreceive()
What visibility must the fallback function have?
Aexternal
Binternal
Cprivate
Dpublic
If a contract has both receive() and fallback(), which handles calls with data?
Areceive()
Bfallback()
CBoth equally
DNeither
What happens if a contract without receive() or fallback() receives Ether?
AEther is stored in fallback
BEther is accepted silently
CTransaction reverts
DContract self-destructs
Which modifier must be used on receive() to accept Ether?
Apayable
Bview
Cpure
Dvirtual
Explain the difference between the receive() and fallback() functions in Solidity.
Think about when each function is triggered based on the data sent.
You got /4 concepts.
    Describe what happens when a contract without receive() or fallback() functions receives Ether.
    Consider the contract's ability to accept Ether without special functions.
    You got /3 concepts.