Skip to Content
Ethereum Cookbook
book

Ethereum Cookbook

by Manoj P R
August 2018
Intermediate to advanced
404 pages
11h 19m
English
Packt Publishing
Content preview from Ethereum Cookbook

Fallback function

Each contract can have one unnamed function called the fallback function. It is executed if no other function matches the given signature or plain Ether is sent to the contract:

  1. Create a fallback function by declaring an unnamed function:
function() {    // fallback function}
  1. In order to receive Ether, mark the fallback function as a payable function. An exception will be thrown by the contract if it does not have a fallback function declared as payable:
function() payable {    // fallback function which can receive Ether}

A contract without a payable fallback function can still receive Ether as a result of self-destruct or mining. Such Ether transfers cannot be rejected by a contract and it is not recommended to use the contract ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Building Ethereum Dapps

Building Ethereum Dapps

Roberto Infante
Ethereum For Dummies

Ethereum For Dummies

Michael G. Solomon

Publisher Resources

ISBN: 9781789133998Supplemental Content