3

In web3js, I can use below code to get private key and wallet address from mnemonic. But how can I get private key if user has mnemonic and extra-word from MEW

const ethers = require('ethers');
let mnemonicWallet = ethers.Wallet.fromMnemonic(mnemonic);

enter image description here

murtza gondal
  • 288
  • 3
  • 12

1 Answers1

3

The "Extra Word" is a BIP-39 passphrase. It looks like you're using Ethers.js, so you can do something like this:

const { utils, Wallet } = require('ethers');

const hdNode = HDNode.fromMnemonic(mnemonic, passphrase).derivePath(utils.defaultPath);
const wallet = new Wallet(hdNode);

The fromMnemonic function does not provide a way to specify a passphrase directly, but this essentially does what fromMnemonic does with the extra passphrase.

Morten
  • 6,017
  • 2
  • 12
  • 26