Decode calldata & return values for ContractCreateTx & ContractCallTx using the aepp-sdk-js

Hi,

for visualizing that within https://aenalytics.org I am currently trying to figure out how to decode this data after the transaction happend, assuming I am not involved in the transaction.

What information is necessary to decode all of the data and how can this be achieved using the aepp-sdk-js?

Example (TESTNET)

Contract

  • ct_2fi1isHPF8mzAzZvGEuFs8TYFLNutbqHuyKRLpCjg75oQknGuD

ContractCreateTx

  • tx-hash
    • th_2onEA5Tq15ZYSLog13G1S84HDEf2LqE8JKCrXHgdU7v3e1KJSZ
  • calldata
    • cb_KxFE1kQfP4oEp9E=
  • code
    • cb_+QLQRgOg/Ckw0vmeni8+5GNpOxl+ge+jZjlwyLnhkPq6Wc6w/nXAuQKiuQHz/ggmfsUCNwL39/cMAwMoHAICKBwAAgIDEZJIUr40AAD+RNZEHwA3ADcAAgMReyZmWg8CghoOhAMBAz/+aHbW3wI3AjcCd/cn5wAn5wEzBAIHDAg2BAIMAQACAxFodtbfNQQCKBwCACgcAAACADkAAAEDA/57JmZaADcARwNeAGY/zJ8BAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFK+CAQEAG2+BiHd3AP6EiW0AADcARwMBAoL+kkhSvgA3AndHBDcAawPaAIICd3cgOAAVSGVsbG8HDA4gOAAJSGkHDAogOAAlR3JlZXRpbmdzBgMGBwwMAQM/DAP/BgMGOh4GCSwgADoqCAAGGgoKgmgPm58BAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACgIId3cBAz8MA/8GAwb+s5nDVgQ3AndHABcLAgAjOAAUBwwEDAKEPAQCZ//YggAUr4IBAQAbZK+CAQEAG2R3dycMBDQChAED/wEDf/7qgX5lADcAB1MAAP7zJL2DADcAJzcADAKEDAMrEQgmfsU/BAMRaHbW37inLwkRCCZ+xREuXjc1EUTWRB8RaW5pdBFodtbfWS5MaXN0SW50ZXJuYWwuZmxhdF9tYXAReyZmWj1yZWdpc3Rlcl9vcmFjbGURhIltAClnZXRfb3JhY2xlEZJIUr5BcmVzcG9uZF90b19ncmVldBGzmcNWMWdyZWV0X29yYWNsZRHqgX5lLWdldF9iYWxhbmNlEfMkvYNFcmVzcG9uZF90b19ncmVldHOCLwCFNC4zLjAAhBFHww==
  • ABI version
    • 3
  • VM version
    • 5

ContractCallTx

  • tx-hash
    • th_3kqL4vWNXYLjPN7hu5YtdsiKRJSRCxJyF5znrLUWjkreghrM2
  • calldata
    • cb_KxGzmcNWKwlIaZ8AoNGhJM4ZHvCOjS2Pv0JFBAE8m4quzsb3F4Xy7iDd86aIGyw4eg==
  • ABI version
    • 3
  • returnValue
    • unknown (how can I retrieve the return value???)

I would appreciate if anybody can help here. Maybe @nduchak.chain and @hanssv.chain can help me? :smiley:

  • is the information I listed above enough the be able to decode the calldata?
  • how can I obtain the returnValue of a ContractCallTx?

As we are using the middleware I know that there is an endpoint that returns a bit more information about the ContractCallTxs for a certain contract. This can for this specific case be retrieved by using the following endpoint:

However, this information currently cannot be retrieved for one specific contract call and additionally there is no possiblity to get the decoded value for the calldata of the ContractCreateTx. That is why I need a way to be able to decode this data by using the aepp-sdk-js or any other client-side library.

Marco

3 Likes

I’ve still never used the JS-SDK for anything non-trivial so I don’t know what can and can not be done there.

There are two APIs for decoding calldata in the HTTP compiler either you need the calldata + contract bytecode or calldata + contract source code in the first case you will get VM-types, but for FATE that is often good enough. The problematic part is user defined (datatype) types. In the second case you will get Sophia types.

1 Like

thanks for the input. in the scenario I am talking about I only know the bytecode in most cases. I will check that and also perform some tests with custom datatypes.

still the question remains how to get the return value for a ContractCallTx. how can I get that with the information mentioned above?

I’m not too familiar with middleware/aeternal @karol.chain might know?

The plain node has an endpoint for getting the call result /transactions/{hash}/info

1 Like

:+1:t2: that should be sufficient

I think for the aepp-sdk-js this is the right place to look at. just if anyone else is trying to achieve the same:

1 Like

New MDW is returning decoded arguments and return value, but old MDW is doing that as well. (at least for ContractCallTx)…

yes but the old/current middleware only returns the decoded values on an endpoint that returns all ContractCallTx of a certain contract.

currently it’s not possible to get the decoded values for a specific transaction. this is at least what I observed when analyzing it.

good to hear that this will be the case in the new middleware :slight_smile:

Hey @marc0olo, so basically you need this two compiler API:

Contract call result can be retrieved using “GetTransactionInfoByHash” Node API

1 Like