1

I'm trying to test one of my functions in a contract which returns a bool value, and in the process of debugging I tried to retrieve the output using console log and I get the following hash:

{ tx: '0x2e5bf10660a50c89eed50cdcf97c23a51845337858223f4d3d1af2495507f661', receipt: { transactionHash: '0x2e5bf10660a50c89eed50cdcf97c23a51845337858223f4d3d1af2495507f661', transactionIndex: 0, blockHash: '0xace406a9b73620b4bf88bf19ba9773dc70f9b32b7e7f9cea4aa4aa9d2018d987', blockNumber: 356, gasUsed: 21958, cumulativeGasUsed: 21958, contractAddress: null, logs: [] }, logs: [] }

Please can somebody help me in understanding what does this mean and a probable fix for this?

Thanks

1 Answer 1

1

If the function on the contract you're calling is not a constant function (e.g. it writes to contract state), you cannot, in general, access the return values of those functions from web3. You can, however, access the return values from other contracts.

To get the return values of contract methods from web3, your options are generally limited to:

  • Emitting an event with the return value
  • Storing the return value and creating a constant getter that allows you to retrieve it later
  • (If you're sure the state won't mutate) Evaluating the call locally and retrieving the result before sending the transaction and committing the state. To do this, you'll have to explicitly use the contract.method.call(...) invocation, rather than just contract.method

The last option is probably not suitable for a contract that can or will change state often. If it's a state machine, for instance, on a per-user basis, evaluating the results locally before sending the transaction is probably safe. If it's something that many people can interact with, your results might not always be accurate.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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