1

Consider this contract

pragma solidity ^0.4.11;

contract GoodAndBad {

  function exec(uint flag) public constant returns (uint) {
    assert(flag == 1);
    return 0;
  }

}

How do I know that calling method exec() using web3.js or geth JSON RPC was successful and I received a number?

If it is not possible what is the best practice for the methods like above?

  • Note that with a constant function, clients will likely try to run it locally instead of issuing a transaction. There is no way for you to collect information about function calls that are run locally on the client. – carver Aug 8 '17 at 18:52
1

You should use event to confirm result, as follows:

pragma solidity ^0.4.11;

contract GoodAndBad {

    uint result = 0;
    event onResult(bool flag,uint result);

    function exec(uint flag) public returns (uint) {
        if (flag != 1) {
            result = 0;
            onResult(false,result);
            return;
        }
        result = 1;
        onResult(true,result);
        return result;
    }

}

and then deploy contract, set a watcher, and call exec method.

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.