Questions tagged [fallback-function]

Questions dealing with the Solidity fallback function

Filter by
Sorted by
Tagged with
17
votes
3answers
5k views

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

Can somebody please explain the differences between using a send and call for contracts and when to use and not use these different methods? For example : msg.sender.send(number); msg.sender....
14
votes
1answer
2k views

How much computation can be done in a fallback function?

Simply sending Ether to a contract, will run the contract's code. In Solidity, this code maps to what it calls the fallback function. How much work can be done in a fallback function?
14
votes
1answer
2k views

Execution of Fallback function with more 2300 gas

I have tested a contract having a fallback function which updated a state variable (cost 5000 gas). I sent an amount of Ether to this contract with 100000 gas limit. The transaction is valid. As ...
11
votes
1answer
2k views

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

I'm trying to get some sense from the hysteria around the attack performed to The DAO smart contract. I understand the high level explanations, but I'd like to grasp how this attack was performed. I'...
9
votes
1answer
762 views

Can you call a base contract's fallback function?

Can you call the fallback function of the base contract that the current contract is inherited from? contract LittleA { function() { doLittleStuff(); // how do I call the base contract's ...
9
votes
1answer
1k views

Send ether reentrancy attack in reality - how could fallback function make a message call back into current contract?

Below is quoted from solidity docs: pragma solidity ^0.4.0; // THIS CONTRACT CONTAINS A BUG - DO NOT USE contract Fund { /// Mapping of ether shares of the contract. mapping(address => ...
9
votes
3answers
920 views

Why is there more than one payable function in a solidity contract?

When someone transfers ether to a contract address the payable callback (without name) function is called automatically. What I don't understand is why are there many examples with multiple payable ...
8
votes
2answers
2k views

Anonymous function in Solidity example code

I'm following this link - https://ethereum.org/token to learn Solidity. The example contract implementation has the following line which I don't understand. Can someone please explain what is this ...
8
votes
2answers
904 views

Fallback function in web3

I find answer how to make upgradable contract here How to call function from currentVersion with fallback function on web3? contract Relay { address public currentVersion; address ...
7
votes
1answer
11k views

What does Solidity's “call” function mean?

address nameReg = 0x72ba7d8e73fe8eb666ea66babc8116a41bfb10e2; nameReg.call("register", "MyName"); //1 nameReg.call(bytes4(sha3("fun(uint256)")), a); //2 if(!nameReg.call.value(10)){throw;} //3 Here ...
7
votes
1answer
8k views

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

This code is in my contract: contract A { address x = 0x1234...; x.send(10); } What would fallback function in the contract at address 0x1234... look like? contract B { ... } ...
7
votes
1answer
906 views

What happens if you call a non-existent function of another contract that has no fallback function in Solidity?

Let's say you call a function at another contract in Solidity: contractB.doFunction() It would then match it using the function signature to run the function in contractB. If there's not match, it ...
7
votes
1answer
1k views

When does the fallback function get called?

Is it true to say that 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? In other words if ...
6
votes
2answers
783 views

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

An empty message still invokes the code of the contract and is the mechanism that allows Solidity to implement a feature of a fallback function per contract. But when msg.data is empty, why does ...
6
votes
1answer
2k views

How does a fallback function rejecting ether work?

A contract in Solidity can have a fallback function like: // This contract rejects any Ether sent to it. It is good // practise to include such a function for every contract // in order not to loose ...
5
votes
1answer
9k views

Send ether to contract address in web3.js

I want to send ether to this contract's contribute function using web3.js I'm trying below code for the same but this doesn't work for me. var AbiOfContract = 'abi_code'; var contractAddress = "...
5
votes
2answers
3k views

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

Here's an example from solidity docs on Address type methods(call method specifically): address nameReg = 0x72ba7d8e73fe8eb666ea66babc8116a41bfb10e2; nameReg.call("register", "MyName"); ...
5
votes
2answers
369 views

Overriding Solidity “send” function

I read that the "send" function in Solidity can be overridden. Why would someone want to do that? Is that a way to avoid execution of the fallback function at the receiver?
5
votes
1answer
631 views

Accessing the last function parameter from msg.data

I have a fallback (unnamed) function in my contract and I know that the last parameter (or first, does not matter) passed is always an uint. Is it possible to somehow access it though the msg.data?
5
votes
1answer
1k views

How do you get a string value from msg.data in the fallback function?

Im trying to do what The DAO did and do something when a sender sent money to my contract address. But im not sure how to. The something I want to do is to just create a new user in a mapping with the ...
5
votes
1answer
919 views

Receiving and manipulating transaction data in smart contract

The idea is simple: you can send transactions using any ethereum wallet, and every such wallet has an additional data to send called "transaction data". For example, I want users to be able to type in ...
4
votes
1answer
3k views

How to pass nested array values to the solidity function?

For Example: I am trying a sample contract where i want to pass nested array values. But i cant able to find the suitable solution ? Is it possible or do i have to change the way to send the ...
4
votes
1answer
73 views

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

Does address.send(0) makes an actual message call forwarding some small amount of gas(2300?) to fallback function or does it simply return false without making a message call to another contract? It ...
4
votes
2answers
217 views

Logging errors in the fallback function

In the code I return any Ether sent by mistake to contract C with the throw; statement inside the fallback function. I also want to make a log of this occasion. The following code doesn't work(throw; ...
4
votes
1answer
755 views

How does a Solidity fallback function work with the raw CALL opcode of the EVM?

Since a fallback function is a Solidity feature, how does it work if the EVM opcode CALL is used? If msg.data is empty, how can Solidity run the fallback function? Shouldn't the EVM just transfer ...
4
votes
1answer
246 views

Is fallback function inheritable?

I just have no means of testing it out myself right now. contract A() { function() { throw; } } contract B is A() {}
4
votes
1answer
179 views

Fallback function gets called when setting contract variables from external node

I’m a beginner in the Ethereum world and I’ve got some problems dealing with a SimpleStorage contract on my private testnet (http://solidity.readthedocs.io/en/latest/introduction-to-smart-contracts....
3
votes
2answers
718 views

How to make function call through relay / entry level contract

I am trying to create an entry level contract (one that is the entry point): Relay.sol pragma solidity ^0.4.8; contract Relay { address public currentVersion; address public owner; ...
3
votes
1answer
2k views

How to trigger contract fallback function from Javascript

For a simple contract: pragma solidity ^0.4.11; contract Test { uint private val; function getVal() constant returns(uint) { return val; } function setVal(uint newVal) payable { ...
3
votes
1answer
785 views

fallback function, best practices when registering information

I'm currently working on a smart-contract, and I have this warning in Remix : Fallback function of contract browser/token.sol requires too much gas (102480). If the fallback function requires more ...
2
votes
2answers
54 views

Fallback function - why revert?

Just wrote and tested the following on http://remix.ethereum.org Same happens on Ropsten network. If I run without sending any value it works, but I can't deploy the Test contract if I put any ...
2
votes
3answers
275 views

why don't popular tokens have payable fallback

I'm referring to the source of of the most popular tokens on etherscan. It looks like they don't have any payable functions. How do they accept ether and transfer the tokens automatically when ...
2
votes
1answer
578 views

fallback function is accepting more than 2300 gas

Quoting from solidity doc: In such a context, there is usually very little gas available to the function call (to be precise, 2300 gas), so it is important to make fallback functions as cheap ...
2
votes
2answers
1k views

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

Hi was going through solidity documentation. There was some code that I was not able to understand, even after researching a lot I was not able to find some satisfactory output. The code is as under: ...
2
votes
1answer
389 views

Fallback function doesn't get called when sending eth

With this code, at the creation of the contract (sending some eth in tx), shouldn't the fallback function be called? Then the state variable feedback shouldn't be "Fallback function correctly called"? ...
2
votes
1answer
294 views

address.transfer no transaction on etherscan

I tested fallback function in my smart contract, and noticed, that there is no transaction on etherscan from smart contract to my account. In short: i try to send money to contract and receive back a ...
2
votes
1answer
1k views

Unable to send ether to contract

I am working on private test-net and trying to send ether to contract but ether is not being transferred. I tried using both geth console and Mist. eth.sendTransaction({from:eth.accounts[0], to: "...
2
votes
1answer
467 views

Truffle send to fallback function from different account

I'm testing a simple fallback function with Truffle, the fallback function is: function () public payable { internalTransfer(this, msg.sender, 100000000); FundSuccess(msg.sender, msg.value); }...
1
vote
2answers
1k views

Fallback function uses too much gas?

I wrote this contract but Remix complains that it uses too much gas. What am I doing wrong? "Fallback function of contract browser/SplitBalance.sol:SplitBalance requires too much gas (40612). If the ...
1
vote
1answer
26 views

How can I reduce the gas price for the fallback function?

Below is my fallback function for ethereum. It currently require 91000 gaslimit which is way more than 21000. Metamask always starts the transaction with 21000 gas stipend due to which transaction ...
1
vote
2answers
56 views

Withdrawal pattern in fallback function

I need to implement withdrawal pattern for my smart contract. I wanted to make it possible to interact with contract for the people, who use smartphones and tables, just by sending some amounts of ...
1
vote
1answer
673 views

TypeError: Fallback function must be defined as “external”

function() public payable{ ^ pragma solidity ^0.5.0; import "./EIP20Interface.sol"; contract InitialTokenOfferingIncomeFAIR is EIP20Interface { uint256 constant private MAX_UINT256 = 2**256 - ...
1
vote
1answer
69 views

Calling nonpayable fallback from web3

Working on some smart contract security cases to become more comfortable with it but am running into an issue. In order to solve this particular puzzle, I need to initiate a fallback function from a ...
1
vote
1answer
25 views

Function argument quantity

Let's say we have a function such as: function tokenFallback(address sender, uint tokenAmount) And some other contract decides to call it with: contract.tokenFallback(sender, tokenAmount, data) ...
1
vote
1answer
55 views

Differences between nameFunction.value and address.transfer

What is the difference between using nameFunction.value(n)(parameters of nameFunction) and address.transfer(10)? I know that in the case of address.transfer, I'll send the amount to the fallback ...
1
vote
1answer
1k views

how to decompile smart contract bytecode?

I don't want the whole bytecode to solidity. I just want that bytecode have fallback function and it's content. is feature in the bytecode about fallback function? about external contract call, ...
1
vote
0answers
18 views

How come the gas usage of an empty fallback function is not integer?

I am trying to compute the gas usage of an empty (i.e., the most basic) fallback function. My on-chain code (compiled via Truffle 4.1.15): pragma solidity 0.4.25; contract MyContract { function(...
1
vote
1answer
31 views

ExecutionFailure in MultiSigWallet contract

I wanted to test a simple use case of MultiSig wallet. To do that I've deployed gnois MultiSigWallet.sol to Rinkeby network. Before testing the multisig functionality I wanted to deposit 0.1 ether to ...
1
vote
2answers
81 views

Difference between transfer to ethereum account or to smart contract?

Is there a difference between sending ether to a user account or to a smart contract. E.g.: contract ThisIsAContract{ function() public payable {} } Now I call (pseudocode) ...
0
votes
1answer
152 views

Why do I need fallback function here?

I have a payable function that transfers ether to contract. function test(...) public payable returns (bool) { ... ...