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
?
[Ethereum] web3.personal.newAccount how to get address
accountsweb3js
Related Topic
- [Ethereum] Get private key from web3.personal.newAccount(‘password’)
- [Ethereum] Web3 create account from mnemonic + passphrase
- [Ethereum] Accounts created by using web3.eth.accounts.create() don’t appear when web3.eth.getAccounts(console.log)
- [Ethereum] Where web3.eth.accounts.create() creates new account
Best Answer
The big difference is:
web3.personal.newAccount
is used to generate addresses on the wallet associated with your node/provider. This is misleading aspersonal
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.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 withweb3.eth.accounts.signTransaction(tx, privateKey)
, but you have to encode any contract data with an encodeABI method first before placing it intx
. 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.