0

I want my website users to have a new ethereum address after registration into my website.

How is it possible with web3 to generate new ethereum address for each user of my website?

Does it require password too while creating new address?

Can i have some sample code?

2 Answers 2

4

You can use web3.eth.accounts.create() to generate something like this

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

Your users will need to store the private key which generates their wallet.

2
  • i tried following code, with address returned, But how can i get that address in a nodejs variable? var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')); web3.eth.personal.newAccount('!@superpassword').then(console.log); > '0x1234567891011121314151617181920212223456'
    – shawn
    Mar 17, 2018 at 10:13
  • using web3.eth.personal.newAccount() creates an account in your server. this is not what you want because the account will be on your server. I understood from your question you actually want the users to store the account. Mar 17, 2018 at 12:14
0

You're best advised to take a look at keythereum. This sample code generates a new key and prints the readable public address.

var keythereum = require("keythereum");
var dk = keythereum.create();
var readableAddress = keythereum.privateKeyToAddress(dk.privateKey);
console.log("public address:" + readableAddress);
console.log("private key in hex:" + dk.privateKey.toString('hex')

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.