I am trying to get the balance of user for specific token type using web3.js.
Here is my code block:
var tokenContract = new web3.eth.Contract(erc20abi, tokenAddress)
tokenContract.methods.balanceOf(accounts[0]).call().then(balance => {
console.log(balance);
});
It throws an error as soon as this function is called from web3.
Following is the error at my console:
Uncaught (in promise) Error: invalid type (arg="type", value="a")
at Object.n [as throwError] (web3.min.js:1)
at D (web3.min.js:1)
at web3.min.js:1
at Array.forEach (<anonymous>)
at web3.min.js:1
at D (web3.min.js:1)
at e.<anonymous> (web3.min.js:1)
at Array.forEach (<anonymous>)
at e.encode (web3.min.js:1)
at a.encodeParameters (web3.min.js:1)**
My web3.js version is: 1.2.7
Here are values from the variables used:
accounts[0] = "0x572ACD5370909b2C0aCde66995c1BE8aC25238bE"
tokenAddress = "0xfd60bC45f816b575C2c938F744CFb801505824E7"
erc20abi = [{ "constant": true, "inputs": [], "name": "name", "outputs": [{ "name": "", "type": "string" }], "payable": false, "type": "function" }, { "constant": true, "inputs": [], "name": "decimals", "outputs": [{ "name": "", "type": "uint8" }], "payable": false, "type": "function" }, { "constant": true, "inputs": [{ "type": "address" }], "name": "balanceOf", "outputs": [{ "type": "uint256" }], "payable": false, "type": "function" }, { "constant": true, "inputs": [], "name": "symbol", "outputs": [{ "name": "", "type": "string" }], "payable": false, "type": "function" }, { "constant": true, "inputs": [{ "internalType": "address", "type": "address" }], "name": "balanceOf", "outputs": [{ "internalType": "uint256", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" } ];
erc20abi
or intokenAddress
or inaccounts[0]
. Check the value of each one of these variables, and make sure that it is legal for the purpose of the corresponding variable.