2

A contract endpoint on Ropsten returns a set like this:

(uint256 _assetId, address _assetOwner, address _issuer, string _content, uint256 _sellPrice, uint256 _status)

The endpoint is getAssetById at can be queried at:

https://ropsten.etherscan.io/address/0xd42e3ac7f89f5904a41cfd19d6505dec77fc2bcd#readContract

I am trying to parse the output for the cases where input is 1 and 2 with the following results:

asset 1:
0000000000000000000000000000000000000000000000000000000000000001 // uint256 _assetId
0000000000000000000000004b0897b0513fdc7c541b6d9d7e929c4e5364d2db // address _assetOwner
0000000000000000000000009b9731b07b9b5f982289bab87097eade6a4bc25d // address _issuer
00000000000000000000000000000000000000000000000000000000000000c0 // string _content ???
0000000000000000000000000000000000000000000000000000000000000000 // uint256 _sellPrice
0000000000000000000000000000000000000000000000000000000000000002 // uint256 _status
0000000000000000000000000000000000000000000000000000000000000016
43726f6d6f20646520546f6e69204d6f72616c2c206e00000000000000000000



asset 2:
0000000000000000000000000000000000000000000000000000000000000002 // uint256 _assetId
0000000000000000000000004b0897b0513fdc7c541b6d9d7e929c4e5364d2db // address _assetOwner
0000000000000000000000009b9731b07b9b5f982289bab87097eade6a4bc25d // address _issuer
00000000000000000000000000000000000000000000000000000000000000c0 // string _content ???
0000000000000000000000000000000000000000000000000000000000000000 // uint256 _sellPrice
0000000000000000000000000000000000000000000000000000000000000002 // uint256 _status
00000000000000000000000000000000000000000000000000000000000000c9
43726f6d6f20646520546f6e69204d6f72616c2c206e756d2e3120646520756e
612074697261646120646520312e20536567756e64612074697261646120656e
20726564206465207072756562617320526f707374656e3b2075726c496d6167
653d27687474703a2f2f692e696d6775722e636f6d2f4d457750436d492e6a70
67273b206861736853484131496d616765566572696669636174696f6e3d2735
6436393131353132623765386332313433316133656263343937323966376536
61653439613338273b0000000000000000000000000000000000000000000000

But the string is messing up things.

Where can I find the length of the string?

Why is part of the string on fourth line and the rest on seventh and nexts?

Any clue to interpret these results? Thx!

Refs.:

Parsing contract method output as an array of fields

7
+50

The length of the string is the word after the one you have identified as status. So for asset1 it is 0x16 = 22 in decimal, and for asset2 it is 0xc9 = 201 decimal.

Strings are dynamic types and have a particular ABI representation as described in the ABI spec. Dynamic data appears after the rest of the data: your string_content ??? word is a pointer to where the string data begins within the returned data, i.e. at byte 0xc0. The string is then represented by a word containing its length in bytes, followed by the string character data itself.

asset 1:
0x00 0000000000000000000000000000000000000000000000000000000000000001 // uint256 _assetId
0x20 0000000000000000000000004b0897b0513fdc7c541b6d9d7e929c4e5364d2db // address _assetOwner
0x40 0000000000000000000000009b9731b07b9b5f982289bab87097eade6a4bc25d // address _issuer
0x60 00000000000000000000000000000000000000000000000000000000000000c0 // pointer to string data starting at 0xc0
0x80 0000000000000000000000000000000000000000000000000000000000000000 // uint256 _sellPrice
0xa0 0000000000000000000000000000000000000000000000000000000000000002 // uint256 _status
0xc0 0000000000000000000000000000000000000000000000000000000000000016 // the length of the string data
0xe0 43726f6d6f20646520546f6e69204d6f72616c2c206e00000000000000000000 // the content of the string data
  • 2
    This answer, while perhaps a bit terse, is correct. You should award the bounty. – Thomas Jay Rush Aug 28 '17 at 22:50
  • 1
    Let me know of any unclarities/overly terse areas and I'll happily expand on this further. – benjaminion Aug 29 '17 at 6:30

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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