Skip to content

Instantly share code, notes, and snippets.

@n1c01a5
Created June 16, 2019 12:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n1c01a5/5247e02a6a8a8370911d033c38238c2a to your computer and use it in GitHub Desktop.
Save n1c01a5/5247e02a6a8a8370911d033c38238c2a to your computer and use it in GitHub Desktop.
function generateSeedWallet() {
const bip39 = require('bip39')
const hdkey = require('ethereumjs-wallet/hdkey')
const mnemonic = bip39.generateMnemonic() //generates string
const seed = bip39.mnemonicToSeedSync(mnemonic).toString('hex')
const hdwallet = hdkey.fromMasterSeed(bip39.mnemonicToSeed(seed))
const wallet_hdpath = "m/44'/60'/0'/0/"
const wallet = hdwallet.derivePath(wallet_hdpath + 0).getWallet()
const address = '0x' + wallet.getAddress().toString('hex')
const privateKey = wallet.getPrivateKey().toString('hex')
return {mnemonic, address, privateKey}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment