Content
@
0 reply
0 recast
0 reaction
Rahul Gupta
@rahul7668gupta.eth
๐งต1/5 ๐ #100DaysOfSolidity #Day11 Solidity has two special functions for handling contract interactions when no other function matches: the fallback function and the receive function. The fallback function is executed when no other function matches the function identifier.
4 replies
0 recast
2 reactions
Rahul Gupta
@rahul7668gupta.eth
๐งต2/5 ๐ #100DaysOfSolidity #Day11 The fallback function has these properties: No name or arguments Must be marked as external Can be payable to receive Ether The receive function must be external and payable but has no name or arguments.
0 reply
0 recast
0 reaction
Rahul Gupta
@rahul7668gupta.eth
๐งต3/5 ๐ #100DaysOfSolidity #Day11 The key difference is the fallback function is for when no other function matches, while the receive function is specifically for plain Ether transfers with no calldata.
0 reply
0 recast
0 reaction
Rahul Gupta
@rahul7668gupta.eth
๐งต4/5 ๐ #100DaysOfSolidity #Day11 Contracts can have at most one fallback function and one receive function. The fallback function can do more complex operations since it has access to calldata, while the receive function is limited to 2300 gas.
0 reply
0 recast
0 reaction
Rahul Gupta
@rahul7668gupta.eth
๐งต5/5 ๐ #100DaysOfSolidity #Day11 It's generally recommended to use the receive function for plain Ether transfers, and the fallback function for interactions where the function selector doesn't match any defined functions. Properly implementing these functions is crucial.
0 reply
0 recast
0 reaction