Skip to main content
Share Your Experience: Take the 2024 Developer Survey
102 votes
Accepted

Fallback function in Solidity

First, payable is a modifier that can be added to a function. What you are most likely misinterpreting is a use case like: function () public payable {} It's impossible to have payable() as a ...
Jakub Wojciechowski's user avatar
60 votes
Accepted

What is the receive keyword in solidity?

TL;DR receive is a new keyword in Solidity 0.6.x that is used as a fallback function that is only able to receive ether. receive() external payable — for empty calldata (and any value) fallback() ...
Shane Fontaine's user avatar
37 votes

Fallback function in Solidity

Update for Solidity ^0.6.0 There have been major changes to the way the fallback function is defined. From the docs: The unnamed function commonly referred to as “fallback function” was split up into ...
Paul Razvan Berg's user avatar
23 votes

What does Solidity's "call" function mean?

Solidity's call is a low-level interface for sending a message to a contract. It returns false if the subcall encounters an exception, otherwise it returns true. There is no notion of a legal call, ...
eth's user avatar
  • 85.9k
22 votes
Accepted

How much computation can be done in a fallback function?

The fallback function can do as much computation as how much gas it gets. There are 2 cases (basically recipient.send and recipient.call{value:...}("")) and case 2 has security implications ...
eth's user avatar
  • 85.9k
17 votes

Execution of Fallback function with more 2300 gas

I was confused by this questions and self answer, so I will try to clarify. The OP sent 1,000,000 gas to a smart contract from an external account. He/she incorrectly read the Solidity documentation ...
Thomas Jay Rush's user avatar
15 votes

send VS call - differences and when to use and when not to use

EDIT Dec 2019: call.value()() should now be used for transferring ether. (Do not use send or transfer.) See: Is transfer() still safe after the Istanbul update?
eth's user avatar
  • 85.9k
15 votes
Accepted

Anonymous function in Solidity example code

This is deprecated syntax that isn't required as of Solidity 0.4.0 function () is the 'default function' or 'fallback function'. If a transaction is sent to an address without transaction data, or if ...
o0ragman0o's user avatar
  • 4,330
14 votes

What's a fallback function when using address.send(...)?

Yay, found it in solidity docs in FAQ section: What is the deal with function () { ... } inside Solidity contracts? How can a function not have a name? This function is called “fallback ...
manidos's user avatar
  • 4,298
12 votes
Accepted

Why does an empty message still invoke the code of the contract?

To keep the core protocol of Ethereum simple and generic, the protocol has the rule that a message always executes the code of an account. Simple and generic allows the critical consensus protocol to ...
eth's user avatar
  • 85.9k
12 votes

Fallback function in Solidity

When someone transfers funds to your contract, the function with payable modifier executes automatically. Here is an example of a payable function. contract token { function () payable { ...
Basit Raza's user avatar
12 votes

Fallback function in Solidity

What exactly does payable() function do? Does this function take arguments? payable() does not exist anymore in Solidity 0.8.x Modifier payable indicates if you can send an amount of ETH when ...
Rutrus's user avatar
  • 251
11 votes
Accepted

Send ether to contract address in web3.js

If you want to accept the Ether in a smart contract then you should have a fallback function. The fallback function will be called by default when someone transfers ETH to the contract address. ...
Karthikeyan Thangavel's user avatar
9 votes

Fallback function in Solidity

Each function with the payable modifier can receive funds. But what if funds are sent to your contract to a non payable function? For this the fallback payable function was defined, which can receive ...
Ilan Dshare's user avatar
7 votes
Accepted

When does the fallback function get called?

In Solidity, yes, if the first four bytes of an Ethereum's transaction does not contain one of the contract's encoded function calls, then the fallback function will be called. Since contract code ...
eth's user avatar
  • 85.9k
7 votes
Accepted

How to pass nested array values to the solidity function?

TL;DR You will have to find an alternative for now if you're making the calls externally as they haven't implemented nested arrays interactions with the call data yet, but it is available in memory/...
James Lockhart's user avatar
7 votes
Accepted

What does msg.sender.call() do in Solidity?

It calls the anonymous fallback function on msg.sender. In a typical reentrancy attack, it would be something like a withdraw function doing msg.sender.call.value(1 ether)(). The caller (a smart ...
user19510's user avatar
  • 28.1k
6 votes
Accepted

Understanding nameReg.call("register", "MyName") style call between contracts

From the link in the question, the important part about nameReg.call("register", "MyName") is (bold mine): to interface with contracts that do not adhere to the ABI, the function call is provided ...
eth's user avatar
  • 85.9k
6 votes

send VS call - differences and when to use and when not to use

address.transfer() reverts on failure forwards 2,300 gas stipend, safe against reentrancy should be used in most cases as it's the safest way to send ether address.send() returns false on failure ...
medvedev1088's user avatar
6 votes

Overriding Solidity "send" function

The send function cannot be overridden, but it does call the callback at the receiving account, if there is code at that address. There's no way to override this, and you shouldn't try - the fallback ...
Nick Johnson's user avatar
  • 8,174
6 votes

Fallback function in web3

You can do this with the sendTransaction function, like so: web3.eth.sendTransaction({ from: sendingAccount, to: contract.address, data: yourData, // optional, if you want to pass data or ...
Steve Ellis's user avatar
  • 1,357
6 votes

fallback function is accepting more than 2300 gas

The fallback function is just like any other function: it gets as much gas as you pass to it. What's different about the fallback function is that it's the one invoked when someone does a simple ...
user19510's user avatar
  • 28.1k
6 votes

What does msg.sender.call() do in Solidity?

msg.sender.call() calls the fallback-function on msg.sender. Here is an example that is extended with a canBeAttacked function. contract Mutex { bool locked; modifier noReentrancy() { require(!...
eth's user avatar
  • 85.9k
6 votes
Accepted

What is (fallback) method in a contract?

The fallback function is the last one in the contract you posted: function() payable { } From https://solidity.readthedocs.io/en/v0.5.10/contracts.html?#fallback-function: A contract can have ...
Daniel Portugal's user avatar
5 votes
Accepted

How to trigger contract fallback function from Javascript

The simplest is to use web3.eth.sendTransaction. Use the contract address for to. Leave data empty (this is the field that determines which function is invoked in a contract). Usually you would ...
eth's user avatar
  • 85.9k
5 votes

What does `call.value` mean and how did it allow the attack to The DAO?

EDIT Dec 2019: call.value()() should now be used for transferring ether. See: Is transfer() still safe after the Istanbul update (2300 gas limitation)? The following is the original answer. ...
eth's user avatar
  • 85.9k
5 votes
Accepted

Can you call a base contract's fallback function?

You can't call things like super() or A() so you have no way to call the unnamed fallback function. However, if you can modify the parent contract, you can move all the logic of your fallback ...
Nicolas Massart's user avatar
5 votes

send VS call - differences and when to use and when not to use

1 Send() does not forward gas anymore. It simply uses the hardcoded stipend (2300 gas) siphoned from the value transfer cost (minimum 9040). It's enough to send ether, but also enough to basically do ...
Badr Bellaj's user avatar
  • 18.8k
4 votes
Accepted

Is fallback function inheritable?

Using Browser-Solidity, I compiled and deployed contract B with the following code: contract A { function() { throw; } } contract B is A() { } I executed a sendTransaction(...) to B (...
BokkyPooBah's user avatar
  • 40.3k
4 votes

Does address.send(0) make an actual call or simply return false?

Update on 09 December 2019: As of today, address.send(0) returns true if call didn't run out of gas. Also it executes the target contract supplying min(gasleft - 700, 2300) gas. Original answer ...
manidos's user avatar
  • 4,298

Only top scored, non community-wiki answers of a minimum length are eligible