首页 > 解决方案 > how can I use encodeFunctionCall()?

问题描述

my function has component(structure) parameter.

{
        "inputs": [
            {
                "components": [
                    {
                        "internalType": "uint32",
                        "name": "total",
                        "type": "uint32"
                    },
                    {
                        "internalType": "uint32",
                        "name": "times0",
                        "type": "uint32"
                    },
                    ...
                ],
                "internalType": "struct Ticket.PackInfo",
                "name": "_packInfo",
                "type": "tuple"
            }
        ],
        "name": "createTicket",
        "outputs": [],
        "stateMutability": "payable",
        "type": "function"
    }

it's abi.

I want to make transaction. so I need to use web3.eth.abi.encodeFunctionCall()

data = web3.eth.abi.encodeFunctionCall({name:'createTicket', type:'function, input:})

What expression should I put in input ?

标签: web3js

解决方案


parameters参数接受一个函数参数数组。

当参数是 astruct时,您需要将其值包装在另一个数组中,并根据结构属性的顺序对它们进行排序。

const parameters = [
    [100, 200] // <total>, <times0>
];

const data = web3.eth.abi.encodeFunctionCall(abiJson, parameters);
console.log(data);

推荐阅读