17

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 and is a key part of how theDAO was attacked and exploited on June 17 2016. Case 1: 2300 gas A recipient contract's fallback function only gets a 2300 gas stipend if it was ...


17

EDIT: Solidity's author, chriseth, recommends to avoid using Solidity's call https://github.com/ethereum/solidity/issues/2884#issuecomment-329169020 The thing is: a.call() is an ancient beast that should not be used. I would recommend using inline assembly for such tasks, since it provides the same security guarantees but does not do any invisible magic. ...


15

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 to say that there was a 'stipend' of only 2300 gas on such a transaction, but that was mistaken. The 'stipend' applies to internal sends from one smart ...


14

Both call the fallback function, but with different amounts of gas "forwarded". msg.sender.send(number); is the same as: msg.sender.call.gas(0).value(number)(); send is safer to use since by default it doesn't forward any gas, so the receiver's fallback function can only emit events. See How much computation can be done in a fallback function? At the ...


13

This is depreciated 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 that data doesn't call a valid function on a contract, the default function is called instead. throw is a depreciated keyword to halt the computation and ...


10

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 function” and it is called when someone just sent Ether to the contract without providing any data or if someone messed up the types so that they tried to call a ...


8

The call will simply return immediately. There will be no code executed, but any value sent with the transaction will remain with the recipient contract. In fact, it will be as if you just sent ether to the contract (note that the value of the transaction can be 0). All extra data (including the ABI) will be ignored.


8

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. contract Crowdfunder{ function() Crowdfunder { } function() payable { contributions.push( Contribution({ amount: msg.value, ...


6

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 which takes an arbitrary number of arguments of any type. These arguments are padded to 32 bytes and concatenated. See the note here: Note: the ABI is an ...


6

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 and the gas stipend exist to provide a way for accounts receiving funds to reject them, or to emit an event to log the transaction. If you send value using ...


6

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 be smaller and decrease the risk of consensus bugs. This means that a detail, such as the Ethereum Contract ABI, does not need to be defined in the core ...


6

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/storage implementations. Internal Nested Uses What this basically means is you can use nested array when they either: Have a storage implementation pragma ...


5

contract.call.gas(...).value(...)(...) is a way to add Ether and limit gas when invoking a contract. Basically, TheDAO used call.value to move Ether around in a generic way. contract.call.value(...)() will invoke the fallback function at contract with almost all the gas that the caller has. In a normal call like contract.foo, if contract is untrusted, it ...


5

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 always runs when a contract gets a message, Solidity effectively featurized it into the fallback function. Note that the Solidity compiler could have "disabled" ...


4

So, when you do address.send(0) the return is always false. The code inside the fallback function of the called contract doesn't run at all. In the example below I couldn't log a value from inside the fallback function even though there was enough gas to do it. contract A { event myLog(bool indexed success); function mySend(address B, uint y){ ...


4

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 one additional small logging operation (in a fallback function). The following operations will consume more gas than the stipend provided to a fallback function:...


4

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 function to another named function that would be called from the callback in A and that would be callable from LittleA. Here is an exemple with two contracts named ...


4

Yes, all parameters can be accessed from msg.data (EVM term is calldata). The calldata is ABI encoded: What is an ABI and why is it needed to interact with contracts? Extracting the first parameter is simpler than others. For the first parameter, skip the first 4 bytes (Method ID), and the next 32 bytes is the uint (left-padded) you are looking for. If ...


4

Any message sent to a contract, even if it is empty or just an ether transfer will invoke the code of the contract. The fallback function is run if the data sent does not start with a known function identifier (e.g. if a non-existent function is called or if the message data is empty as is the case for a simple ether transfer). So if a contract has a ...


4

The fallback function is a feature of the Solidity language, and is not an EVM-level feature. Solidity simply parses the msg.data field in transactions according to the ABI:bytes4(sha3("functionName(argTypes)")) When the code is compiled, the ABI signatures are stored in the compiled code, and when the code is called, it looks to see if the first four bytes ...


4

That function is called the "fallback" function. It is the function that is invoked when a transaction with no data field is made to a contract. Notice that there is no "payable" modifier on that contract. When you label a function as "payable" it is a function that invokable with a non-zero Ether value in the "value" field of the transaction. The reason ...


3

Code is run as a response to a transaction. This always happens when there is code in the account. msg.data being empty doesn't mean no code should be called, there is no such "rule", it only means there is no input.


3

IF the fallback function only gets 2300 gas, it can't write to contract storage and here are 2 ideas. Option 1 You could add an explicit function like receiveEther(string senderName) in the contract. web3.js can be used like contractInstance.receiveEther("name of the sender", {value: web3.toWei(1, "ether"), ...}) and the contract could access the sender ...


3

address.transfer() throws 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 forwards 2,300 gas stipend, safe against reentrancy should be used in rare cases when you want to handle failure in the contract address.call.value().gas()() ...


3

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 (fallback) and the Out Of Gas error was thrown. So the answer is Yes.


3

Since I have only 2300 gas available I can't call another contract that will make a log. Is it correct? The basic cost for calling another contract is 700 gas (cost of CALL opcode). So it's probably possible to call another contract to do the logging, but that extra level of indirection might just be clutter. What's not possible is writing to storage, ...


3

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 specify the amount of wei value, but you can omit this if you just want to invoke the fallback function. Fallback functions are not intended to be used the way ...


3

Yes, from Relay you can call Access2 functions, like createEntity. The important code in Relay that makes it happen is its fallback-function: function() { if(!currentVersion.delegatecall(msg.data)) throw; } It is helpful to read the questions and answers on fallback-function to learn more about them. Basically, when you invoke (call) createEntity in ...


3

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 specify another function to be called by delegateCall you do that here gas: requiredGas, // technically optional, but you almost certainly need more than the ...


3

The fallback (default/unnamed) function in Solidity only has by default a gas allowance of 2300 gas - which is about enough to create an event log: If a contract receives Ether (without a function being called), the fallback function is executed. ... During the execution of the fallback function, the contract can only rely on the “gas stipend” (2300 gas) ...


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