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.


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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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