[Ethereum] create ether wallet using nodejs

ethereum-classicethereum-wallet-dappmyetherwalletweb3js

I have implemented the code which is creating new wallet but I am not able to get the private key of that wallet. Can anyone tell me like what is the proper way in which I can create new wallet which can provide me the private key as well using node.

my code:-

web3.personal.newAccount(name, function (err, res) {
        if (err) {
            next(err,null);
        } else {
            next(null , res);
        }
    });

Best Answer

//generate private key    
privateKey = web3.eth.accounts.create().privateKey.substr(2)

//generates pubKey from privateKey, encrypts it and store in keystore folder.
web3.eth.personal.importRawKey(privateKey, pin)
    .then((result) => {

    //store pub address.
    publicAddr = web3.utils.toChecksumAddress(result)
})

Sort of a similar question was also posted here: How to generate Ethereum wallets & keys on serverside with JS?

Related Topic