5

I know the basics of blockchain and how to use geth. However, I'm curious to know how to build a wallet using nodejs. What I basically is that you can create a account using geth console (private network) to work on and when pass command "personal.listWallets" then you will this :Output of the personal.listWallets in geth console

So, If anyone can tell me what is HD wallet and how to create one by using node.js. Thanks in advan

2

You can also use the highly convenient HDWalletProvider library from the Truffle team

const HDWalletProvider = require("truffle-hdwallet-provider");
const Web3 = require('web3');

var mnemonic = "opinion destroy betray ..."; // 12 word mnemonic
var provider = new HDWalletProvider(mnemonic, "http://localhost:8545");

const web3 = new Web3(provider);

HD wallets can be convenient, since you can generate an infinite number of deterministic accounts, but never lose these 12 words or you will lose all access to use your signatures and ether

  • There is also a caveat around word selection. You should not pick arbitrary words, but words from a word bag that assures randomization. If I find a link, I'll post it here. – GViz Dec 17 '18 at 23:55
9

HD Wallets refer to Hierarchical Deterministic wallets. They are wallets that from a root it can generate multiple "child" private keys in a deterministic way. You only need to remember the "path" of the child key.

For example hardware wallets use them from a single root you can generate separate keys for Bitcoin (with path m/44'/0'/0'/0) and Ethereum (path m/44'/60'/0'/0).

A javascrip library that support HD wallets ethereumjs-wallet.

var hdkey = require("ethereumjs-wallet/hdkey")
var bip39 = require("bip39");

// You can generate a mnemonic seed with bip39 library
var mnemonic = "seed sock milk ...";
var path = "m/44'/60'/0'/0/0";

var hdwallet = hdkey.fromMasterSeed(bip39.mnemonicToSeed(mnemonic));
var wallet = hdwallet.derivePath(path).getWallet();
var address = "0x" + wallet.getAddress().toString("hex");

console.log(address);
  • Is there any documentation of that? Like how to add more accounts, get private key/password of account, recover wallet from seed etc? – Prashant Prabhakar Singh Jan 2 '18 at 5:59
  • @PrashantPrabhakarSingh Ethereumjs-wallet has a decent documentation and has unit test for hdkey wallets but otherwise the source code is good as documentation. – Ismael Jan 2 '18 at 16:50
  • @Ismael how could we add this with Geth. – Shivam Nema Jan 18 '18 at 20:44
  • @ShivamNema Once you have created the wallet you can export the private key and import it in geth. But it is better if you say what are you trying to accomplish in the end, ie why do you want to use a HD wallet? They are used when you need a large number of addresses, and geth has no support for the special properties of hd wallets. – Ismael Jan 20 '18 at 16:06

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.