First of all, i extracting function from abi of my contract and calling them automatically. As per documentation of solidity, when we compile .sol, some functions are automatically generated as per our contract specs. For, example, if i write in my contract mapping( address => uint256) public balances
, it will generate function namely balances and taking address as input (argument). When my program call this function (with properly given valid address), it causes error. I am confused why I could not find any solution for this. Although i have given all kind of inputs as per requirement of my contract. Still getting such error.
Here is my code
async function genericGetterFunction(receipt, key){
var funcParmLength
var myFunc;
var myContAddr = receipt.contractAddress;
var myContractAbiDefenition = sources[key].abi;
var myContractInstance = new web3.eth.Contract(myContractAbiDefenition, myContAddr);
for(j=0; j < getterFunctionsNameObject[key].length; j++){
myFunc = getterFunctionsNameObject[key][j].func;
funcParmLength = (getterFunctionsNameObject[key][j].input).length;
console.log("param length: ", funcParmLength)
if (funcParmLength ==0)
res = await myContractInstance.methods[myFunc]().call({from: account1, value: web3.utils.toWei('0', 'ether')})
else
res = await myContractInstance.methods[myFunc](getterFunctionsNameObject[key][j].input).call({from: account1, value: web3.utils.toWei('0', 'ether')})
console.log("Normal Order output", res);
}
output of console.log(getterFunctionsNameObject);
[ [ { contract: 0, func: 'balances', input: [Array] },
{ contract: 0, func: 'getTotalSupply', input: [] },
{ contract: 0, func: 'owner', input: [] },
{ contract: 0, func: 'totalSupply', input: [] } ] ]
output of console.log(getterFunctionsNameObject[0]);
[ { contract: 0,
func: 'balances',
input: [ '0x2cAe18ac37d85CccdE2ebB63D0c391Fe1ac7c36f' ] },
{ contract: 0, func: 'getTotalSupply', input: [] },
{ contract: 0, func: 'owner', input: [] },
{ contract: 0, func: 'totalSupply', input: [] } ]
output of console.log("function Name: ", myFunc)
: function Name: balances
output of console.log("param length: ", funcParmLength)
: param length: 1
output of console.log("arguments: ", getterFunctionsNameObject[key][j].input)
arguments: [ '0x2cAe18ac37d85CccdE2ebB63D0c391Fe1ac7c36f' ]
Here is my error:
UnhandledPromiseRejectionWarning: Error: invalid address (arg="", coderType="address", value=["0x2cAe18ac37d85CccdE2ebB63D0c391Fe1ac7c36f"])
at Object.throwError (C:\Users\aa\Desktop\temp\node_modules\ethers\utils\errors.js:68:17)
at CoderAddress.encode (C:\Users\aa\Desktop\temp\node_modules\ethers\utils\abi-coder.js:467:20)
at C:\Users\aa\Desktop\temp\node_modules\ethers\utils\abi-coder.js:605:59
at Array.forEach (<anonymous>)
at pack (C:\Users\aa\Desktop\temp\node_modules\ethers\utils\abi-coder.js:604:12)
at CoderTuple.encode (C:\Users\aa\Desktop\temp\node_modules\ethers\utils\abi-coder.js:764:16)
at AbiCoder.encode (C:\Users\aa\Desktop\temp\node_modules\ethers\utils\abi-coder.js:897:77)
at ABICoder.encodeParameters (C:\Users\aa\Desktop\temp\node_modules\web3-eth-abi\src\index.js:96:27)
at C:\Users\aa\Desktop\temp\node_modules\web3-eth-contract\src\index.js:432:24
at Array.map (<anonymous>)
at Object._encodeMethodABI (C:\Users\aa\Desktop\temp\node_modules\web3-eth-contract\src\index.js:431:12)
at Object._processExecuteArguments (C:\Users\aa\Desktop\temp\node_modules\web3-eth-contract\src\index.js:747:39)
at Object._executeMethod (C:\Users\aa\Desktop\temp\node_modules\web3-eth-contract\src\index.js:772:54)
at genericGetterFunction (C:\Users\aa\Desktop\temp\deploy1.js:212:99)
at main (C:\Users\aa\Desktop\temp\deploy1.js:152:17)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:6276) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:6276) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.