Skip to content

Instantly share code, notes, and snippets.

@GrandSchtroumpf
Created May 13, 2018 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GrandSchtroumpf/fe5b6764606c2259e3e8966f1c04b48a to your computer and use it in GitHub Desktop.
Save GrandSchtroumpf/fe5b6764606c2259e3e8966f1c04b48a to your computer and use it in GitHub Desktop.
A HDWallet for Ethereum
const bip39 = require('bip39');
const HDKey = require('hdkey');
const Web3 = require('web3');
const web3 = new Web3('https://ropsten.infura.io/your-id');
const mnemonic = bip39.generateMnemonic();
confirm(mnemonic);
const seed = bip39.mnemonicToSeed(mnemonic);
const masterNode = HDKey.fromMasterSeed(seed);
const derivationKey = "m/44'/60'/0'/0'/0";
const account = masterNode.derive(derivationKey);
const privateKey = account._privateKey.toString('hex');
const web3Account = web3.eth.accounts.privateKeyToAccount(privateKey);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment