4

I want to create a new account via code (Node.js), so I ran the following code, which was copy-pasted from the docs:

web3.eth.accounts.create();

How ever accounts' value is an empty array, and therefore I'm getting this error:

web3.eth.accounts.create is not a function

which makes sense because Array doesn't have a method named create.

How do I create a new account?

2

2 Answers 2

3

I think you are using web3 version prior to 1.0. as i know web3.eth.accounts.create() was introduced in web3 1.0. so check your web3js version. if you have a prior version use web3.eth.personal.newAccount(password, [callback]) documented here

4
  • For some reason npm installs version 0.20.2 by default. In that version the right command is neither of the above but: web3.personal.newAccount(password, [callback]). What a DLL hell! What would you recommend me to do? Use my current version or upgrade to 1.0 (if it's possible at all)
    – Alon
    Nov 9, 2017 at 16:17
  • try npm install [email protected]
    – Badr Bellaj
    Nov 9, 2017 at 16:32
  • it throws stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
    – Alon
    Nov 9, 2017 at 16:53
  • this is a nodejs issue stackoverflow.com/questions/21365714/…
    – Badr Bellaj
    Nov 9, 2017 at 17:38
1

separate the "password" and "callback result" arguments of each other

web3.eth.personal.newAccount(password,(result)=>{
    console.log(result);
    res.send(JSON.stringify(result));        
});

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.