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

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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