OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

how to use tuple type in eth_abi encode

  • Thread starter Thread starter Ruzaini Subri
  • Start date Start date
R

Ruzaini Subri

Guest
I want to encode below data with eth_abi but I cannot get the correct way to map its data type.

here is my attempt but I got error on tuple

Code:
order_types = [('address maker','uint8 kind','tuple(uint8 erc,address addr,uint256 id,uint256 quantity) assets','uint256 expiredAt','address paymentToken','uint256 startAt','uint256 basePrice','uint256 endedAt','uint256 endedPrice','uint256 expectedState','uint256 nonce','uint256 marketFeePercentage')]

Here is my data.

Code:
    from eth_abi import encode
   

    order_data = [
    Web3.to_checksum_address(order.maker),
    1,
    [
        [
            1,
            Web3.to_checksum_address(order.assets[0]['address']),
            int(order.assets[0]['id']),
            int(order.assets[0]['quantity'])
        ]
    ],
    int(order.expiredAt),
    Web3.to_checksum_address(address),
    int(order.startedAt),
    int(order.basePrice),
    int(order.endedAt),
    int(order.endedPrice),
    0,
    int(order.nonce),
    int(marketplace_fee)
    ]


   encode(order_types, [order_data])

Can you advise how can I get the correct data type
Thank you in advance.
<p>I want to encode below data with eth_abi but I cannot get the correct way to map its data type.</p>
<p>here is my attempt but I got error on tuple</p>
<pre><code>order_types = [('address maker','uint8 kind','tuple(uint8 erc,address addr,uint256 id,uint256 quantity) assets','uint256 expiredAt','address paymentToken','uint256 startAt','uint256 basePrice','uint256 endedAt','uint256 endedPrice','uint256 expectedState','uint256 nonce','uint256 marketFeePercentage')]
</code></pre>
<p>Here is my data.</p>
<pre><code> from eth_abi import encode


order_data = [
Web3.to_checksum_address(order.maker),
1,
[
[
1,
Web3.to_checksum_address(order.assets[0]['address']),
int(order.assets[0]['id']),
int(order.assets[0]['quantity'])
]
],
int(order.expiredAt),
Web3.to_checksum_address(address),
int(order.startedAt),
int(order.basePrice),
int(order.endedAt),
int(order.endedPrice),
0,
int(order.nonce),
int(marketplace_fee)
]


encode(order_types, [order_data])
</code></pre>
<p>Can you advise how can I get the correct data type<br />
Thank you in advance.</p>
 

Latest posts

Top