1

I have a Solidity contract with a method that changes the state of the contract. This method normally returns a value. But web3 gives me txHash, net the return value. Do I have a way to receive that value?

myContract.incrData.sendTransaction(function (err, result) {
    var txhash = result;  // <-- I need return value, not the tx hash
})
1

But web3 gives me txHash, net the return value.

The sendTransaction method always returns a transaction hash whether the transaction is to a contract or an account. This is because when you send the transaction, the contract is not executed till mining is done, because of which it cannot get the return values till your transaction is mined.

Do I have a way to receive that value?

You can use events to get the values from the contract. Details on how to emit events can be found at https://media.consensys.net/technical-introduction-to-events-and-logs-in-ethereum-a074d65dd61e

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.