ape
ape copied to clipboard
feat: add return value for transactions
Overview
Provide a simple overview of what you wish to see added. Please include:
Upon making a test for ERC20 Smart contract. We should add a return value for accounts.
tx = contract.myMutableMethod(...)
assert tx.return_value == ... # .return_value doesn't exist
- What you are trying to do
- Why Ape's current functionality is inadequate to address your goal
Specification
Describe the syntax and semantics of how you would like to see this feature implemented. The more detailed the better!
Remember, your feature is much more likely to be included if it does not involve any breaking changes.
Dependencies
Include links to any open issues that must be resolved before this feature can be implemented.
You have to use events for transactions I believe.
https://ethereum.stackexchange.com/questions/73787/solidity-return-value-of-smart-contract-transact
I showed @Ninjagod1251 how to get the events from a receipt!
You have to use events for transactions I believe.
https://ethereum.stackexchange.com/questions/73787/solidity-return-value-of-smart-contract-transact
I showed @Ninjagod1251 how to get the events from a receipt!
Not sure if this is event related, might require traces actually... I think the trick is to decode the debug_traceTransaction
one level and obtain the last structLog item which should contain the return value. Can also use evm-trace
to return
https://github.com/eth-brownie/brownie/blob/3aecd87f47c9c316c85b0b0c6252ff7d900cca74/brownie/network/transaction.py#L274-L275
Look like we should research more and I think I might be in over my head. I would love to listen in and test the feature
Look like we should research more and I think I might be in over my head. I would love to listen in and test the feature
Yeah, please hold off on this for now
this can be quite easily done now
def get_return_value(tx):
call_tree = chain.provider.get_call_tree(tx)
method_abi = Contract(call_tree.address).contract_type.mutable_methods[call_tree.calldata]
output = chain.provider.network.ecosystem.decode_returndata(method_abi, call_tree.returndata)
if isinstance(output, tuple) and len(output) < 2:
output = output[0] if len(output) == 1 else None
return output
@helloibis might be able to take a stab at adding this to the ReceiptAPI
class as a .return_value
property, and let it raise if the current provider does not implement .get_call_tree