web3js - 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 ?
解决方案
该parameters
参数接受一个函数参数数组。
当参数是 astruct
时,您需要将其值包装在另一个数组中,并根据结构属性的顺序对它们进行排序。
const parameters = [
[100, 200] // <total>, <times0>
];
const data = web3.eth.abi.encodeFunctionCall(abiJson, parameters);
console.log(data);
推荐阅读
- javascript - 如何让 webpack 在每次更改时重建 server.js 并让 nodemon 重新启动服务器?
- javascript - 从base64节点js转换后.txt文件开头出现一些随机字符
- unity3d - Unity Shader Graph - 跟随对象形状的Grandient
- routes - TYPO3 felogin - 如何通过 Hook 将 preserveGETvars 或 redirect_url 设置为实际页面?
- x509 - 单个 PKI 可以与多个证书策略相关联吗?
- flutter - 颤振中的提供者层次结构
- python - Python:将一个numpy数组写入txt文件
- java - 如何使用 bufferedreader 和 treeset 从文本中显示不同单词的数量?
- javascript - 从另一个页面使用 AJAX 来操作数据库
- python - 按键后如何让我的程序复制输出?