2

Let's say I've created an account using this code as explained in docs:

web3.eth.accounts.create();
> {
    address: "0xb8CE9ab6943e0eCED004cDe8e3bBed6568B2Fa01",
    privateKey: "0x348ce564d427a3311b6536bbcff9390d69395b06ed6c486954e971d960fe8709",
    signTransaction: function(tx){...},
    sign: function(data){...},
    encrypt: function(password){...}
}

How do I connect (unlock) to that account later and see all the ETH and other tokens it contains?

Achala Dissanayake
  • 5,819
  • 15
  • 28
  • 38
Alon
  • 277
  • 1
  • 3
  • 8

1 Answers1

3

To get the Ether Balance use web3.fromWei(eth.getBalance(acct), "ether")

The following links might give a guide on checking token balance.

http://nuclearcryptobuddha.blog/2017/06/how-to-send-receive-and-check-balance-of-erc20-tokens-using-geth/

https://lightrains.com/blogs/useful-ethereum-geth-javascript-snippets

How do I print my account balances and TheDAO tokens from geth

I haven't actually tried it.

Achala Dissanayake
  • 5,819
  • 15
  • 28
  • 38
  • Thank you for your help. A few things aren't clear to me yet. 1) Once I create an account I get a private key and an encryption method. Should I use the encrypt method on the spot and save its result to use later? 2) when I unlock the account, you mentioned a password, but what about the private key? 3) how do I connect the two commands you wrote together? Does personal.unlockAccount return an 'eth' object? – Alon Nov 08 '17 at 16:55
  • you have to store the key in local storage encrypted using a password and decrypt with the password when needed to sign a transaction. here https://web3js.readthedocs.io/en/1.0/web3-eth-accounts.html#eth-accounts-signtransaction to sign a transaction you need only the private key and no password. You use the password to store the private key in secure. as doc says >privateKey - string:This should never be shared or stored unencrypted in localstorage! – Achala Dissanayake Nov 08 '17 at 17:37
  • unlocking an account means getting the private key to sign data or transactions . – Achala Dissanayake Nov 08 '17 at 17:43
  • Not yet, I cannot test it yet since I'm stuck in an earlier step, as you can see here: https://ethereum.stackexchange.com/questions/30245/invalid-json-rpc-response-undefined – Alon Nov 09 '17 at 08:00
  • Yes I have, but I cannot test it yet, since I'm stuck in another earlier step, as you can see here: https://ethereum.stackexchange.com/questions/30275/server-resources-needed-to-run-geth-part2 – Alon Nov 09 '17 at 11:26
  • 1
    I've deleted this question because I solved it by myself. Now I face with another problem, I will test your code as soon as I get my program run at all. – Alon Nov 09 '17 at 19:20
  • I have not tested it yet. Yesterday I just managed to solve another problem I'd had: https://ethereum.stackexchange.com/questions/30296/web3-accounts-create-is-not-a-function/30302?noredirect=1#comment32423_30302 – Alon Nov 24 '17 at 10:33
  • While trying to adopt the suggested answer, I came across a very tough problem which I had to open a bounty on SO for. I also had some troubles to adopt the suggested answer in that question, but yesterday I've finally made it: https://stackoverflow.com/questions/47256033/tracker-error-trk0005-failed-to-locate-cl-exe-the-system-cannot-find-the/47304700?noredirect=1#comment81836873_47304700 – Alon Nov 24 '17 at 10:36
  • OK I've tested it. web3.eth.getBalance(address) throws an error: Invalid JSON RPC response: "" – Alon Nov 24 '17 at 11:49