Skip to content

Instantly share code, notes, and snippets.

@pedrouid
Created August 14, 2019 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pedrouid/7cd16c967308a354f2767f1764ee43cf to your computer and use it in GitHub Desktop.
Save pedrouid/7cd16c967308a354f2767f1764ee43cf to your computer and use it in GitHub Desktop.
Example with ethers.js (Ethereum Wallet)
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;
}
@PhatJay76
Copy link

PhatJay76 commented Oct 2, 2021

HI - Wouldn't one want some ability to increment the activeIndex value? ...in the case of using multiple wallets (accounts) from the same mnemonic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment