4

When a contract calls another contract, are values returned ? I've seen things like:

function foo() external returns (bool success) {
    if( ... ) throw;
    return true;
}

But have read that calls to other contracts return either false if the call fails, or true if the call succeeds, meaning the returns (bool success)and return trueare redundant.

eth
  • 85,679
  • 53
  • 285
  • 406
vera34
  • 157
  • 1
  • 1
  • 3

1 Answers1

3

Yes, a contract will get the return value when it invokes another contract in the usual way, as in address.foo().

What you have read about, is the use of Solidity's lower-level call function [example: address.call(bytes4(sha3('foo()')))], which will not return the value from foo.

return true may seem redundant, but it is helpful when using web3.js to invoke foo. With web3.js, one could use web3.eth.call first to invoke foo. If true is obtained, then invoke foo with web3.eth.sendTransaction. Had the return true not been included in the source code of foo, this technique would not be possible.

Supplementary information: What is the difference between a transaction and a call?

eth
  • 85,679
  • 53
  • 285
  • 406