Can someone please shed light on what I might be doing wrong here? I'm trying to query the token balance of an account using geth (v1.7.2) and I'm doing the following but I get invalid address even though the address is correct of both the address and the token.
The following are the steps im doing.
Thanks for your help.
Set default account
> web3.eth.defaultAccount = web3.eth.accounts[0];
"0x41f32f70119e9deead9681d371207cae0b2c16f6"
Unlock Account
> web3.personal.unlockAccount(web3.eth.accounts[0], "PASSWORD", 3600);
true
Set Token's ABI
> tokenabi = web3.eth.contract([{"constant": "true","inputs": [{"name":"","type":"address"}],"name":"balanceOf","outputs":[{"name": "","type": "uint256"}],"payable":"false","stateMutability":"view","type":"function"}]);
{
abi: [{
constant: "true",
inputs: [{...}],
name: "balanceOf",
outputs: [{...}],
payable: "false",
stateMutability: "view",
type: "function"
}],
eth: {
accounts: ["0x41f32f70119e9deead9681d371207cae0b2c16f6", "0x77ca2e7e9aa9f0494560ed0eacbe1b1b90f9fcb6"],
blockNumber: 10887,
coinbase: "0x41f32f70119e9deead9681d371207cae0b2c16f6",
compile: {
lll: function(),
serpent: function(),
solidity: function()
},
defaultAccount: "0x41f32f70119e9deead9681d371207cae0b2c16f6",
defaultBlock: "latest",
gasPrice: 0,
hashrate: 0,
mining: false,
pendingTransactions: [],
protocolVersion: "0x3f",
syncing: false,
call: function(),
contract: function(abi),
estimateGas: function(),
filter: function(options, callback, filterCreationErrorCallback),
getAccounts: function(callback),
getBalance: function(),
getBlock: function(),
getBlockNumber: function(callback),
getBlockTransactionCount: function(),
getBlockUncleCount: function(),
getCode: function(),
getCoinbase: function(callback),
getCompilers: function(),
getGasPrice: function(callback),
getHashrate: function(callback),
getMining: function(callback),
getPendingTransactions: function(callback),
getProtocolVersion: function(callback),
getRawTransaction: function(),
getRawTransactionFromBlock: function(),
getStorageAt: function(),
getSyncing: function(callback),
getTransaction: function(),
getTransactionCount: function(),
getTransactionFromBlock: function(),
getTransactionReceipt: function(),
getUncle: function(),
getWork: function(),
iban: function(iban),
icapNamereg: function(),
isSyncing: function(callback),
namereg: function(),
resend: function(),
sendIBANTransaction: function(),
sendRawTransaction: function(),
sendTransaction: function(),
sign: function(),
signTransaction: function(),
submitTransaction: function(),
submitWork: function()
},
at: function(address, callback),
getData: function(),
new: function()
}
Define Token Instance
> tokeninst = tokenabi.at(0xd27716ebAdDaE1902C45878803A5c3582426ada3);
{
abi: [{
constant: "true",
inputs: [{...}],
name: "balanceOf",
outputs: [{...}],
payable: "false",
stateMutability: "view",
type: "function"
}],
address: 1.201543847219371e+48,
transactionHash: null,
allEvents: function(),
balanceOf: function()
}
Validate Address with Balance
> web3.isAddress("0x41f32f70119e9deead9681d371207cae0b2c16f6");
true
Validate Token Contract Address
> web3.isAddress("0xd27716ebAdDaE1902C45878803A5c3582426ada3");
true
Query Balance of Address
> balance = tokeninst.balanceOf.call("0x41f32f70119e9deead9681d371207cae0b2c16f6");
Error: invalid address
at web3.js:3930:15
at web3.js:3734:22
at web3.js:5025:28
at map (<native code>)
at web3.js:5024:12
at web3.js:5050:18
at web3.js:5075:23
at web3.js:4102:22
at <anonymous>:1:11
Have also tried it with
> balance = tokeninst.balanceOf("0x41f32f70119e9deead9681d371207cae0b2c16f6");
Error: invalid address
at web3.js:3930:15
at web3.js:3734:22
at web3.js:5025:28
at map (<native code>)
at web3.js:5024:12
at web3.js:5050:18
at web3.js:5075:23
at web3.js:4102:22
at apply (<native code>)
at web3.js:4227:12
What do you reckon is wrong / missing here with my steps ?
tokenabiis a misnomer, since it's a contract object. And note that theaddressfield in the return value oftokenabi.atis a number. – user19510 Apr 07 '18 at 05:30{ abi: [{ constant: "true", inputs: [{...}], name: "balanceOf", outputs: [{...}], payable: "false", stateMutability: "view", type: "function" }], address: "0xd27716ebAdDaE1902C45878803A5c3582426ada3", transactionHash: null, allEvents: function(), balanceOf: function() }
– Tanveer Roowala Apr 08 '18 at 22:36