-
-
Save alexanderattar/fb9b19be9d918ac963d74e42e5d42632 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 = 0; | |
function generatePath(index) { | |
const path = `${standardPath}/${index}`; | |
return path; | |
} | |
function generateMnemonic() { | |
const entropy = ethers.utils.randomBytes(16); | |
const mnemonic = ethers.utils.entropyToMnemonic(entropy); | |
return mnemonic; | |
} | |
function createWallet() { | |
const mnemonic = generateMnemonic(); | |
const path = generatePath(activeIndex); | |
const account = ethers.Wallet.fromMnemonic(mnemonic, path); | |
return account; | |
} | |
function createWallets(numWallets) { | |
const accounts = []; | |
const mnemonic = generateMnemonic(); | |
for (let i = activeIndex; i < numWallets; i++) { | |
const path = generatePath(i); | |
accounts.push(ethers.Wallet.fromMnemonic(mnemonic, path)); | |
} | |
return accounts; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment