Fallback
fallback
is a function that is called when a function to call does not exist.
For example, call doesNotExist()
, this will trigger the fallback function.
Receive Ether
fallback
function declared as external payable
is commonly used to enable the contract to receive Ether.
There is a slight variation of the fallback
called receive
.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
contract Fallback {
string[] public answers = ["receive", "fallback"];
fallback() external payable{}
receive() external payable {}
}
Last updated
Was this helpful?