I want to convert a 24 words length seed phrase into a private key using web3.
Asked
Active
Viewed 2.5k times
1 Answers
25
Here are two options:
Using ethers.js - the example below uses a mnemonic ethers wallet documentation
const ethers = require('ethers');
let mnemonic = "YOUR MNEMONIC";
let mnemonicWallet = ethers.Wallet.fromMnemonic(mnemonic);
console.log(mnemonicWallet.privateKey);
This doesn't seem to be included in web3, but has been added to the list of enhancements for 2.0. There are some options described in this thread.
Update Mar 31, 2022
As of ethers@6.2.3, the api now uses fromPhrase instead of fromMnemonic:
const ethers = require("ethers");
const mnemonic = "YOUR MNEMONIC";
const mnemonicWallet = ethers.Wallet.fromPhrase(mnemonic);
console.log(mnemonicWallet.privateKey);
Wallet.fromPhrase(mnemonic)– 0xPingo Mar 31 '23 at 04:03