Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solidity now supports a Recieve & Fallback callback function #292

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,25 @@ function() payable { emit LogDepositReceived(msg.sender); }
// good
function() payable { require(msg.data.length == 0); emit LogDepositReceived(msg.sender); }
```
Solidity now supports a [receive fallback](https://docs.soliditylang.org/en/v0.8.14/contracts.html#receive-ether-function)
function, which when declared in your code you wouldn't need to worry about making your main fallback function payable.
Receive fallback function will be triggered when Ether is forcefully sent to the contract.<br/>
It can be declared by:
```
receive() external payable { ... }
```

There is now also an explicit [fallback function](https://docs.soliditylang.org/en/v0.8.14/contracts.html#fallback-function),
that replaces the normal fallback function.
This gets triggered when a function call does not match any of the function signatures declared in a contract.
This fallback function can also be assigned payable to accept Ether.<br/>
It can be declared by:
```
fallback() external { ... }
```