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

7
  • Please explain "extra-word from MEW". Commented Jun 15, 2020 at 6:37
  • while creating wallet from myetherwallet's mnemonic method for wallet creation, there is option to choose extra word along with 12 or 24 words mnemonic. Commented Jun 15, 2020 at 6:41
  • What is that word used for? Commented Jun 15, 2020 at 6:47
  • Does this answer your question? How can I get a private key from a mnemonic phrase?
    – Masoud jt
    Commented Jun 15, 2020 at 6:52
  • That's not the same question! Commented Jun 15, 2020 at 6:52

1 Answer 1

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.

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.