2
pragma solidity ^0.4.6;

contract Demo {

    uint a;

    function set(uint b) returns (uint) {
        a = b;
        return a * b;
    }

    function get() constant returns (uint) {
        return a;
    }
}

Q: The function "get()" is a constant function, it is not changed the contract status, it just return the "a" value, when the function "set(uint b)" called, it will return a transaction hash, and wait to the mined, so then, how to capture the return value "a * b" ? Many blogs and answer say it can't captured, but use event can do this, But a online compiler can do this, https://ethereum.github.io/browser-solidity , and how the browser-solidity did it ? enter image description here

0

1 Answer 1

0

These return values are not available to external clients in the case of a sendTransaction. The return value is the transaction hash which indicates a transaction was submitted for verification.

So, if they're not accessible, why have them?

Other contracts can read these values. External clients can read these values when they .call() functions in read-only ("dry run") mode. For example, it might be useful to confirm return true; using contract.function.call() and then send a transaction with contract.function().

There are design patterns for coping with the unknown result. Leaving that out as it's straying off-topic.

Hope it helps.

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