How to import wallet using mnemonic?

  • fromMnemonic

This function is used extract the details of account using a secret phrase.

const { ethers } = require("ethers");

const standardPath = "m/44'/60'/0'/0";
const activeIndex = 1;

const path = `${standardPath}/${activeIndex}`;

const hdNode = ethers.HDNodeWallet.fromPhrase("YOUR_PHRASE");

const wallet = ethers.HDNodeWallet.fromMnemonic(hdNode.mnemonic, path)

Parameters:

The phrase needs to be passed in order to get the details.

"YOUR_PHRASE"

Returns:

A promise that resolves when trying to extract the data from mnemonic.

{
    "provider": null,
    "address": "0xC02431F63CE5BbbFc78AD45B5b11981f294FfC23",
    "publicKey": "YOUR_PUBLIC_KEY",
    "fingerprint": "0xcd7af7eb",
    "parentFingerprint": "0x602dde3d",
    "mnemonic": "YOUR_MNEMONIC",
    "chainCode": "YOUR_CHAIN_CODE",
    "path": "m/44'/60'/0'/0/1",
    "index": 1,
    "depth": 5
}

Last updated