【问题标题】:solidity, how to send tuple array data to contractsolidity,如何将元组数组数据发送到合约
【发布时间】:2021-08-17 01:19:57
【问题描述】:

我的代码:

{
    "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"
}

这个 abi 接收一个元组数组作为输入数据。

所以,我尝试根据数据条件进行编码。

我怎样才能发送到数据元组数组???

【问题讨论】:

    标签: solidity abi contract


    【解决方案1】:

    如果您从 JS 库发送值,则只需传递 JS 对象数组即可。使用web3 的示例:

    const id = 1;
    const attr = [
        {trait_type: 'foo', display_type: 'bar', value: 1}
    ];
    
    await contract.methods.pushAttribute(id, attr).send();
    

    【讨论】:

      猜你喜欢
      • 2020-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多