MetaMask – How to Recover a 2nd Account in MetaMask

ethermetamask

This question is not about how to recover, but how does metamask recover my 2nd account?

my setup:

windows 10
latest chrome browser
latest metamask plugin
goerli testnet

I had set up a metamask wallet with 2 accounts on computer A. I got

   paraphrase
   Account 1
   Account 2

Both accounts had ETH balances.

Now I wanted to make them accessible from computer B.

On computer B,

1. I installed metamask plugin into my browser. 
2. I used the paraphrase (got from computer A) to restore my wallet in metamask.
3. this restored my Account 1.
4. To restore "Account 2", I clicked "Create Account", and typed "Account 2" as name. 
5. This didn't create a new account, 
6. but actually restored my "Account 2" from computer A, and I saw my ETH balance.

How did this work? or where metamask stored or retrieved "Account 2" information?

Best Answer

The mnemonic phrases are specified in bip-39

This BIP describes the implementation of a mnemonic code or mnemonic sentence -- a group of easy to remember words -- for the generation of deterministic wallets.

It means you can generate the accounts 0,1,2,3,... (the private keys) from the paraphrase always the same.

The derivation path is used to generate the private key:

m/purpose'/coin_type'/account'/change/address_index

For Ethereum, the values are predefined - except for the address_index - which is the account number, and look like this (account 0)

m/44’/60’/0’/0

So to generate any account 0,1,... for the mnemonic it would be with ethers library:

ethers.Wallet.fromMnemonic(myMnemonic, `m/44'/60'/0'/${accountNumber}`);
Related Topic