[Ethereum] How to encode tuple parameters

abietherscanweb3js

I found many tools to encode parameters online, but besides web3 and thus Etherscan, none of them supports tuples/struct. And my problem is I’m unable to find the correct syntax.

So obviously :

[['0xe750ad66de350f8110e305fb78ec6a9f594445e3', '0xe750ad66de350f8110e305fb78ec6a9f594445e3', 120000000000, 120000000000, 9609897722, 21141030548170097311423986196179119918205185312506968352714471828911136365707, 0x415565b0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee00000000000000000000000000000000000000000000000009346106f8b94959000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000, 5263421676475549035, '0x0000000000000000000000000000000000000000', 0]]

isn’t the correct syntax. But then where’s my mistake ? The struct is declared here https://etherscan.io/address/0x5A66a1bE5de85e770d2A7AaC6d1d30e39D4f6609#code#F25#L30.

Best Answer

Heres is what you can do.

With ethers you can encode a call like this.

const orderTuple = [
        orderJson.makerAddress,
        orderJson.takerAddress,
        orderJson.feeRecipientAddress,
        orderJson.senderAddress,
        orderJson.makerAssetAmount,
        orderJson.takerAssetAmount,
        orderJson.makerFee,
        orderJson.takerFee,
        orderJson.expirationTimeSeconds,
        orderJson.salt,
        orderJson.makerAssetData,
        orderJson.takerAssetData,
        orderJson.makerFeeAssetData,
        orderJson.takerFeeAssetData
]
    
    
const signature = orderJson.signature     
const iface = new ethers.utils.Interface(JSON.stringify(FILL_ORDER_ABI));
 const sig = "fillOrder((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),uint256,bytes)";

const data = iface.encodeFunctionData(sig,[orderTuple,fillAmount,signature])

This is an example that encode a call ready to be sent.

You can probably use it as an example to encode your data call and see the output.

Related Topic