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

1
  • " 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 Dec 11, 2016 at 23:58

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.