3

Shouldn't this be possible as the return value will be known when the receipt is created?

1
  • 1
    I can think of two possible reasons: 1) a contract can return an arbitrary amount of data, 2) The result is redundant (for example tx receipts are also not stored in the blockchain). Since you can always create a log entry with the result, perhaps creating a special log with the return value is not a bad idea.
    – Ismael
    Commented Mar 19, 2018 at 21:57

1 Answer 1

3

If you have a function which does not need the blockchain (or EVM) to get the return value, then you can get it directly. Such functions are view and pure functions. Those functions get the value from your own node and there's no need to go through the EVM.

If the function is not pure or view, then it will go through EVM execution - it has to be mined in a block. Therefore the execution is not instant and you can only get the return value after the transaction is mined in a block.

3
  • 1
    It would still be nice if the interface would allow for return values of transactions to be passed to javascript. If I invoke a contract in Solidity I can get the return value. Is that because even the invocation of the contract is considered part of the same transaction so it's all internal? I assume so. But the library could still be done in a way that would allow access to return values. For instance, by automatically turning return values into events and automatically parsing the events after mining. Commented Mar 19, 2018 at 13:56
  • 4
    "and you can only get the return value after the transaction is mined in a block." That's what OP is asking for: a return value in the transaction receipt (once the block is mined). But no, a return value is not available for transactions.
    – user19510
    Commented Mar 19, 2018 at 16:31
  • 1
    Is there a good reason for this beyond "the value included in the transaction needs to resolve on the blockchain"? What if you (hypothetically) want to return a value that isn't involved in the transaction? That seems like a relatively reasonable feature to be included? Commented May 30, 2022 at 19:20

Your Answer

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

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