0

There are two ways to create account one is web3.eth.accounts.create() and web3.eth.personal.newAccount(); function, When I use newAccount() function account is created in my local geth client but when I used create() function nothing happens.

Edit : from web3.eth.accounts.newAccount() to web3.eth.personal.newAccount();;

1

Everything below is relevant for web3.js v1.x.

There is no such function web3.eth.accounts.newAccount().

There is function web3.eth.personal.newAccount().

The difference is that function web3.eth.accounts.create() merely returns an object with an account credentials, while web3.eth.personal.newAccount() creates an actual account on the node, via an RPC (remote-procedure call) to a node process (e.g., Parity, Geth, Ganache, etc).

Due to the above, function create is synchronous by nature and returns the result immediately, while function newAccount is asynchronous by nature and returns a Promise object which must be resolved (waited for) in order to obtain the result.

So you will technically be doing:

  • const accountObject = web3.eth.accounts.create(...);
  • const accountAddress = await web3.eth.personal.newAccount(...);

Here is the official documentation:

  • I edited my question, it was my mistake – Rishabh Singh May 27 at 18:54
  • @RishabhSingh: No need to apologize for that (whether it was a mistake or not). Just make sure that you understand the answer. – goodvibration May 27 at 19:23
  • yaha I understand the answer, but what is the use of create() function if it not actually creating anything? And I tried newAccount() It create and store the private key in geth node, suppose these node is not locally but remotely somewhere else then my private key is exposed. – Rishabh Singh May 28 at 7:49
  • @RishabhSingh: create generates an account object with private key and public key. This is actually quite useful, if you want to get yourself a new (random) account. You could also read this in the documentation that I have linked in the answer. – goodvibration May 28 at 8:21

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.