I am trying to do a contract call with some parameters. I do this with a NodeJS Express API.
The code looks as following:
var array = JSON.parse(req.body.arguments);
getContractFromABIAndAddress(req.body.abi, req.body.contractAddress, function(contract) {
contract.methods[req.body.method](array).send({from: config.publickey}).on('receipt', function(receipt) {
res.json({
txHash: receipt.transactionHash,
contractAddress: receipt.contractAddress,
txURL: config.etherscantransaction + receipt.transactionHash,
contractURL: config.etherscanaddress + receipt.contractAddress
})
});
})
The req.body.arguments
contains the needed parameters and the req.body.method
contains the right method to call on the contract.
I can test the code with postman, the body would look like the following picture.
Now as you can see here: Web3 Contract docs,
I am using the second option. myContract.methods['myMethod(uint256)'](123)
The problem is that I can't send multiple parameters, the contract needs the parameters like this: myContract.methods['myMethod(uint256,uint256)'](2,2)
but I am giving them like this myContract.methods['myMethod(uint256,uint256)']([2,2])
.
This results in the following:
Which means that the contract call is only getting one parameter according to the error logs and to the web3-eth-contract library. This can be solved by doing the following:
Which turns my parameters back to the right format:
If the Web3 library would get an update now, my NodeJS API wouldn't work anymore because I have been messing with the library. I can't find any other way to give the parameters with the contract call, or with contract send, since the problem also exists over there.
Could someone help me out?