Metamask uses one seed phrase to generate other accounts. Thus, with one seed phrase you can restore all accounts. But what is the algorithm for this?

I want a script that could show 10 of my accounts from metamask using one seed phrase. I want to see the address and seed phrase of each account.

1 Answer 1


It's done like this:

import hdkey from 'ethereumjs-wallet/src/hdkey';
import * as bip39 from 'bip39'

const seedPhrase = process.env.SEED_PHRASE;
const walletsCount = 4;

const masterKey = hdkey.fromMasterSeed(await bip39.mnemonicToSeed(seedPhrase));

for (let i = 0; i < walletsCount; i++) {
  const wallet = masterKey.derivePath(`m/44'/60'/0'/0/${i}`).getWallet();
  const address = `0x${wallet.getAddress().toString('hex')}`;
  const privateKey = `0x${wallet.getPrivateKey().toString('hex')}`;

  console.log(`Address #${i}: ${address}`);
  console.log(`PrivateKey #${i}: ${privateKey}`);

Where "m/44'/60'/0'/0/" is BIP44.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.