0

I setup a private chain and deploy an erc20 contract. I tried sending transaction of balanceOf and can get nothing but a transaction number as the return value. how can i get the balance of erc20 on geth console? My code is given below FYI

var contract = eth.contract(abi).at(eth.accounts[0])
contract.balanceOf.sendTransaction(eth.accounts[0],{from:eth.accounts[0],gas:60000})
3
  • You need to call the function, rather than send a transaction. I'm not sure what programming language you're using, so it's hard to help further.
    – user19510
    Jul 11 '18 at 6:10
  • Consider sharing your existing code.
    – user19510
    Jul 11 '18 at 6:11
  • @smarx I paste my code . I also tried call balanceOf locally, the return value is 0.
    – user41635
    Jul 11 '18 at 6:24
0

(i'm gonna assume that you are using the web3.js... since that's what your snippet looks like.)

checking the balance doesn't require you to send a transaction

just use

contract.balanceOf(myaddress)

and it should give you the balance of the token for your address (eth.accounts[0])

1
  • As an alternative, contract.balanceOf.call(myAddress) should work. (Using neither sendTransaction or call lets web3.js choose the right thing for you, but it's okay to be explicit.)
    – user19510
    Jul 11 '18 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.