2

I am trying to create an account in the blockchain for a new User who will be using my dapp.

I am using the web3 1.x version so it has a method web3.eth.accounts.create() which returns somehting like this :

{
    address: "0xb8CE9ab6943e0eCED004cDe8e3bBed6568B2Fa01",
    privateKey: "0x348ce564d427a3311b6536bbcff9390d69395b06ed6c486954e971d960fe8709",
    signTransaction: function(tx){...},
    sign: function(data){...},
    encrypt: function(password){...}
}

Also web3 has the method web3.personal.newAccount() which only returns an account address.

Now i want to know why there are two and what difference they have between each other ?

1 Answer 1

4

web3.personal.newAccount() calls personal_newAccount on your node

Taken from geth doc

Generates a new private key and stores it in the key store directory. The key file is encrypted with the given passphrase. Returns the address of the new account.

web3.eth.accounts.create() generates the account data without communicating with an ethereum node. That's why it returns the private key , because there's no account manager to handle your accounts / keys

7
  • so the account created via web3.eth.accounts.create() is not a usuable account ? what did you mean about account manager. Mar 12, 2018 at 10:17
  • Both accounts are usable. One is created inside the node web3 is talking to (geth / parity) the other account is returned to you but not managed by the node. Mar 12, 2018 at 10:57
  • What do you exactly mean by "managed". Mar 12, 2018 at 15:02
  • geth saves, encrypts, loads and unlocks the accounts for you. The are saved as files on your local filesystem. You don't need to know where they are because geth knows and manages interaction with your accounts. With web3.eth.accounts.create() geth does not know about the account. It is your responsability to store, load and use the account generated Mar 12, 2018 at 15:59
  • So, if i am right, if an account X is not managed by geth then running web3.eth.accounts won't return X. Mar 13, 2018 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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