The fallback function

In Solidity, there is another special method, which is the fallback function. It's an unnamed function that cannot have arguments, nor return anything, and it is declared as follows: function () public payable { }.

The fallback function is executed if the contract is called and no function in the contract matches the specified function's signature. This is not a mandatory function to declare, but you can include it, in order to define your contract's behavior when it receives transactions without data. To accepts funds, you have to declare it as payable.

If your contract will be called by another contract, you can't put much code into your fallback function. At most, you can define an event log, as for security reasons, it only has access to a 2,300 gas stipend.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset