3

If I do web3.personal.newAccount("passphrase") from my code then how can I get back the address that was created using my passphrase? Moreover can anyone tell me the difference of web3.personal.newAccount & web3.eth.accounts.create both are creating accounts and if by second method i store the key in keystore then how can I unlock the account using web3.personal.unlockAccount ?

2

Moreover can anyone tell me the difference of web3.personal.newAccount & web3.eth.accounts.create both are creating accounts and if by second method i store the key in keystore then how can I unlock the account using web3.personal.unlockAccount?

The big difference is:

  1. web3.personal.newAccount is used to generate addresses on the wallet associated with your node/provider. This is misleading as personal method is not necessarily local. Do not use this method unless you are running your own node (i.e. Geth or Parity). If you are using Infura or similar provider service, I doubt you'd want to create a wallet account on their node.

  2. web3.eth.accounts.create will generate a local key pair. If you use this method, definitely make sure to store your key info, as it is only kept TEMPORARY in memory. You can then send transactions with web3.eth.accounts.signTransaction(tx, privateKey), but you have to encode any contract data with an encodeABI method first before placing it in tx. This is not a recommended method, and this approach is used under the hood by browser-based wallet providers like Metamask.

To query the list of accounts controlled by your node wallet use web3.eth.getAccounts(). I need to look into how you can get a list of locally generated addresses.

1

If I do web3.personal.newAccount("passphrase") from my code then how can I get back the address that was created using my passphrase?

addr = w3.personal.newAccount("passphrase")

Moreover can anyone tell me the difference of web3.personal.newAccount & web3.eth.accounts.create both are creating accounts and if by second method i store the key in keystore then how can I unlock the account using web3.personal.unlockAccount?

Sorry, can't help you with that - but FWIW I couldn't make web3.eth.accounts.create work at all.

0

You can get a list of accounts created through web3.eth.accounts, listed in chronological order of creation.

  • But it at that time may be some other already created a one then? Is there no way to get the address back? – Sidhartha Majumder Sep 21 '17 at 18:37
  • Sidharthat's question is about web3.personal, i.e. local accounts. – David Ammouial Oct 4 '17 at 23:38

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.