6

Hello I want to create a ether wallet account using node js and web3. Can anyone please help me in this regard. Thanks in advance!

2 Answers 2

4

Try this,

1st make sure you have web3 installed.

npm install web3

then add the following to one of your nodejs files.

var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));

web3.eth.personal.newAccount('!@superpassword').then(console.log);
> '0x1234567891011121314151617181920212223456'
4
  • Thanks for the reply.I got this error Cannot read property 'newAccount' of undefined. I am working in ropsten test environment .Could you pls help further
    – Ravi Verma
    Dec 20, 2017 at 12:22
  • you will need to ensure that you start geth with the right parameters that allow you to access "personal". Have a look at this command | geth --identity "MyNodeName" --rpc --rpcport "8080" --rpccorsdomain "127.0.0.1" --rpcapi "db,eth,net,web3,personal" --networkid 1999 console | note the word "personal" if your node has not explicitly been told to allow access then trying to call web3.eth.personal will not work.
    – Lismore
    Dec 20, 2017 at 12:29
  • It does not return private key. Can you please tell how can i get that?
    – Ravi Verma
    Dec 22, 2017 at 10:05
  • You should be able to find that answer by doing some googling
    – Lismore
    Dec 23, 2017 at 22:23
4

The correct way to create a Wallet Address is as follows: Assume you already have your web3 object connected.

createWallet = cb => {
  cb(web3.eth.accounts.create());
};

Then call it like this

createWallet(result => {
  console.log("Wallet Add is:", result.address);
  console.log("Private Key is:", result.privateKey);
});

Hope that helps. This article also helps to distinguish: This article should help understand the difference between the 2 methods. Difference between creation methods

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.