'Issue in calling a smart contract function with web3

Im trying to call the createCustomer function provided in this smart contract https://ropsten.etherscan.io/address/0xD3B462CbF6244ed21CD3cF334Bf8CB44A28795A9#code

and we basically have to provide three parameters like string memory _hashedEmail, string memory _name and string memory _phone.

So i've written the following program to call the createCustomer function


const addcustomer = async (req, res, next) => {
  try {
        const init = async() => {
            const provider = new  HDWalletProvider(
              privateKey1,
              'https://ropsten.infura.io/v3/1693cef23bd542968df2435f25726d39'
            );
            const web3 = new Web3(provider);

            let contract = new web3.eth.Contract(abi2, address3);
            contract.methods.createCustomer({_hashedemail: "a", _name: "nike", _phone: "99"}).call((err, result) => { console.log(result) });
            };
            init(); 
    }catch (err) {
        //throw error in json response with status 500. 
        return apiResponse.ErrorResponse(res, err);
    }
};

However it gives me this err which doesnt make any sense as i've already provided the three paramaters.

(node:14744) UnhandledPromiseRejectionWarning: Error: Invalid number of parameters for "createCustomer". Got 1 expected 3!


Solution 1:[1]

Remove the { } inside createCustomer. So to be clear, this line:

contract.methods.createCustomer({_hashedemail: "a", _name: "nike", _phone: "99"})

should be:

contract.methods.createCustomer(_hashedemail: "a", _name: "nike", _phone: "99")

plus, when you try to interact with a function that modify the blockchain you shouldn't call it using .call but instead with .send.

To learn more you should check the web3.js docs

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Niccolò Fant