如何调用带有多个参数的合约函数?
How to call a contract function with multiple arguments?
我正在尝试调用接受 3 个参数的 Solidity 合约函数。
这是我的合约函数的样子。
function test(string memory a, string memory b, string memory c) public{
// Does something here (alters the data in the contract)
}
我现在正在尝试使用 web3 版本 1.2.1 向此函数发送交易,但我遇到了错误。
instance = await new web3.eth.Contract(JSON.parse(abi), address);
instance.methods.test("hello_a","hello_b","hello_c").sendTransaction({from:account});
代码在 async() 块中,传递的所有参数都是正确的。但是我收到一条错误消息,说 sendTransaction 不是测试的函数。
我在这里错过了什么?
您应该使用 send
而不是 sendTransaction
instance.methods.test("hello_a","hello_b","hello_c").send({from:account});
您可以阅读有关可用方法的更多信息there
我正在尝试调用接受 3 个参数的 Solidity 合约函数。 这是我的合约函数的样子。
function test(string memory a, string memory b, string memory c) public{
// Does something here (alters the data in the contract)
}
我现在正在尝试使用 web3 版本 1.2.1 向此函数发送交易,但我遇到了错误。
instance = await new web3.eth.Contract(JSON.parse(abi), address);
instance.methods.test("hello_a","hello_b","hello_c").sendTransaction({from:account});
代码在 async() 块中,传递的所有参数都是正确的。但是我收到一条错误消息,说 sendTransaction 不是测试的函数。
我在这里错过了什么?
您应该使用 send
而不是 sendTransaction
instance.methods.test("hello_a","hello_b","hello_c").send({from:account});
您可以阅读有关可用方法的更多信息there