As we know you can't get the return value of a non-constant function Still ERC20 does this a lot, for example:

 function approve(address _spender, uint256 _value) returns (bool success)

Hypothesis: return values are only there for contract-to-contract calls, and since you can't return anything from a transaction it is useless if not called by contracts.

Is this true? Are contract to contract calls with return values possible? And should you then always have a (Event, return) pair in this cases?

  • 1
    contract-to-contract calls happen within the same transaction, so I'd assume return values are possible. Aug 17 '16 at 12:43

Yes, contract to contract return values are possible. Let's say you have this contract:

contract Tool {
    function numberIsEven() returns (bool);

We now call it from another contract:

import "Tool.sol";

contract Caller {
    Tool public tool;
    uint public saved;

    function Caller(address _tool) {
        tool = Tool(_tool);
        saved = 0;

    function changeNumber() {
        if (tool.numberIsEven()) {
            saved = 2;
        } else {
            saved = 1;

Within your tests you can check what saved value is kept in the Caller contract.

I have created a small repo to demonstrate it. Look at the contracts and the tests, which contain comments.


Following strictly the definitions of contracts, no, a contract (method) calling another contract (state changing method) is indistinguishable (functionally) from an externally owned account doing the same thing (both types of accounts use the same transaction mechanism to perform calls).

All state changing method calls return their transaction hash since they perform operations that alter the block chain. The changed state must be read in a separate transaction.

  • That's a hell of an information. Makes the ERC20 thing even more mysterious. Do you have a citation to add? Aug 17 '16 at 13:08
  • The standard offers a number of methods tokens can implement, but tokens are just contracts (having the same access to block chain variables as "usual" contracts). The proposed methods can return a value if implemented as a set of consecutive methods (one state changing method and one "reader" method called by the same token method) but functionality-wise the "write" method always returns a transaction hash.
    – Sebi
    Aug 17 '16 at 13:38
  • whaaa, eli5 plz! Aug 17 '16 at 13:57

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.