Search code examples
ethereumsolidityweb3js

How to call a contract function with multiple arguments?


I am trying to call a function of my Solidity contract that takes in 3 arguments. Here's what my contract function looks like.

function test(string memory a, string memory b, string memory c) public{
 // Does something here (alters the data in the contract)
}

I am now trying to use web3 version 1.2.1 to send a transaction to this function but I'm encountering errors.

instance = await new web3.eth.Contract(JSON.parse(abi), address);
instance.methods.test("hello_a","hello_b","hello_c").sendTransaction({from:account});

The code is in an async() block and all the arguments passed are correct. However I get an error saying sendTransaction is not a function of test.

What am I missing out here?


Solution

  • You should use send instead of sendTransaction

    instance.methods.test("hello_a","hello_b","hello_c").send({from:account});
    

    You can read more about available methods there