2

Is this (syntax 1):

feed.info.value(10).gas(800)();

equivalent to (syntax 2):

feed.sendTransaction({value: 10, gas: 800, from: address(this)})

?

In which case, how will the Consumer contract have the 10 eth in the first place since it has no payable function?

I saw the first of these lines in the infofeed example here:

contract InfoFeed {
  function info() payable returns (uint ret) { return 42; }
}
contract Consumer {
  InfoFeed feed;
  function setFeed(address addr) { feed = InfoFeed(addr); }
  function callFeed() { feed.info.value(10).gas(800)(); }
}

If there are equivalent, suppose InfoFeed.info() were to take some arguments. How could we send the value of these argument using the first syntax please?

Thanks

hartmut
  • 488
  • 5
  • 15
  • " In which case, how will the Consumer contract have the 10 eth in the first place since it has no payable function?" It won't. The transaction will fail – Tjaden Hess Dec 11 '16 at 23:58

1 Answers1

2

It is a message call, which is similar to a transactions

Contracts can call other contracts or send Ether to non-contract accounts by the means of message calls. Message calls are similar to transactions, in that they have a source, a target, data payload, Ether, gas and return data. In fact, every transaction consists of a top-level message call which in turn can create further message calls. https://solidity.readthedocs.io/en/latest/introduction-to-smart-contracts.html#message-calls

The code is described here, where you see the difference of an internal function call which is a jump in the EVM and an external call, a message call: https://solidity.readthedocs.io/en/latest/control-structures.html#external-function-calls

To understand message calls as nested parts of a transaction but not real transactions, see also part 4 of this answer: https://ethereum.stackexchange.com/a/770/264 What etherscan.io calls internal transactions thus are message calls.

Roland Kofler
  • 11,638
  • 3
  • 44
  • 83