solidity, how to send tuple array data to contract

Viewed 920

my code :

{
    "constant": false,
    "inputs": [
        {
            "name": "_id",
            "type": "uint256"
        },
        {
            "components": [
                {
                    "name": "trait_type",
                    "type": "string"
                },
                {
                    "name": "display_type",
                    "type": "string"
                },
                {
                    "name": "value",
                    "type": "uint8"
                }
            ],
            "name": "_attr",
            "type": "tuple[]"
        }
    ],
    "name": "pushAttribute",
    "outputs": [],
    "payable": false,
    "stateMutability": "nonpayable",
    "type": "function"
}

This abi receives a tuple array as input data.

so, I tried encoding according to the data condition.

how can i make send to data tuple array???

1 Answers

If you're sending the value from a JS library, you can just pass an array of JS objects. Example using web3:

const id = 1;
const attr = [
    {trait_type: 'foo', display_type: 'bar', value: 1}
];

await contract.methods.pushAttribute(id, attr).send();
Related