Return values from functions which create transactions, can only be true or false, at least when you check them post transaction (e.g., with web3 through receipt). However, when functions call each other on the EVM, even through external function calls, multiple non-boolean return values can be passed on from function to function. Why is that?
1 Answer
Transaction receipts only have a status field which can be 0 or 1. There is simply no field for a return value.
To navigate around this, you can:
- use events
- replay the call at a specific block (see
myContractInstance.myMethod.call(param1 [, param2, ...] [, transactionObject] [, defaultBlock] [, callback])in https://github.com/ethereum/wiki/wiki/JavaScript-API#contract-methods)
- Thanks, I've deployed events to get around this limitation. The second option involves the call method which fetches data from the client without sending a transaction. It's strange to me that this method will provide return values, but a
sendwon't. It's just a single extra–yet highly valuable–field. Just because there is no field doesn't mean mean there shouldn't be:)Garen– Garen2018-10-04 17:43:11 +00:00Commented Oct 4, 2018 at 17:43 - Yes. It‘s quite limiting. There is also no possibility to return an error code on revert. Which is really painful. However, there are plans to extend this.ivicaa– ivicaa2018-10-04 17:48:34 +00:00Commented Oct 4, 2018 at 17:48
- It looks like require and revert allow passing of error messages that bubble up: solidity.readthedocs.io/en/v0.4.25/… Do you mean catching exceptions is not yet possible?Garen– Garen2018-10-05 22:51:41 +00:00Commented Oct 5, 2018 at 22:51
- 1See this one: ethereum.stackexchange.com/questions/40993/…ivicaa– ivicaa2018-10-06 04:51:50 +00:00Commented Oct 6, 2018 at 4:51