Created
August 14, 2019 19:03
-
-
Save pedrouid/7cd16c967308a354f2767f1764ee43cf to your computer and use it in GitHub Desktop.
Example with ethers.js (Ethereum Wallet)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ethers = require('ethers') | |
const standardPath = "m/44'/60'/0'/0"; | |
const activeIndex: number = 0; | |
function generatePath() { | |
const path = `${standardPath}/${activeIndex}`; | |
return path; | |
} | |
function generateMnemonic() { | |
const entropy = ethers.utils.randomBytes(16); | |
const mnemonic = ethers.utils.HDNode.entropyToMnemonic(entropy); | |
return mnemonic; | |
} | |
function createWallet() { | |
const mnemonic = generateMnemonic(); | |
const path = generatePath(); | |
const account = ethers.Wallet.fromMnemonic(mnemonic, path); | |
return account; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HI - Wouldn't one want some ability to increment the activeIndex value? ...in the case of using multiple wallets (accounts) from the same mnemonic