New to blockchain software development? Read my beginners guide here

What are the fallback() and receive() functions in Solidity

Created on May 2022 β€’ Tags: ethereumsolidityguides

A guide on Solidity's fallback and receive functions

Table of Contents for What are the fallback() and receive() functions in Solidity

Receive function in solidity

receive() external payable {
// .. your logic here
  • The receive() function was added in Solidity 0.6.0.
  • It is used as a fallback function when eth is sent to a smart contract
  • It is used only when there is ether sent to a smart contract, and no calldata was sent.
  • (if call data was sent, it will fall back to fallback())

Fallback function in Solidity

fallback() external payable {
// .. your logic here
  • If you call a function that does not exist on a smart contract (from another contract), then it will attempt to run the fallback function (if it was defined).

Further reading

Spotted a typo or have a suggestion to make this crypto dev article better? Please let me know!

See all posts (70+ more)

See all posts (70+ more)

Was this post helpful? πŸ“§

If you liked this content and want to receive emails about future posts like this, enter your email. I'll never spam you.

Or follow me on @CryptoGuide_Dev on twitter

By using this site, you agree that you have read and understand its Privacy Policy and Terms of Use.
Use any information on this site at your own risk, I take no responsibility for the accuracy of safety of the information on this site.