What is wrong here?
const userWalletKeys = Wallet.createRandom().mnemonic
const userWallet = ethers.Wallet.fromMnemonic(userWalletKeys.phrase)
I get this error at line 2 of code:
Uncaught TypeError: ethers__WEBPACK_IMPORTED_MODULE_3__.Wallet.fromMnemonic is not a function
I tried to generate a random mnemonic phrase for a ether wallet.
What is wrong here?
const userWalletKeys = Wallet.createRandom().mnemonic
const userWallet = ethers.Wallet.fromMnemonic(userWalletKeys.phrase)
I get this error at line 2 of code:
Uncaught TypeError: ethers__WEBPACK_IMPORTED_MODULE_3__.Wallet.fromMnemonic is not a function
I tried to generate a random mnemonic phrase for a ether wallet.
Share Improve this question asked Mar 8, 2023 at 23:34 Radu BogdanRadu Bogdan 312 silver badges2 bronze badges4 Answers
Reset to default 3In the version 6.1.0 you need to use
const wallet = ethers.Wallet.fromPhrase(mnemonic.phrase)
This would return a new HDWallet for you , that would consist of the public and private keys.
const wallet = ethers.Wallet.fromPhrase(mnemonic);
const privateKey = wallet.privateKey;
const publicKey = wallet.publicKey
The syntax changed in v6. Instead of
const userWallet = ethers.Wallet.fromMnemonic(userWalletKeys.phrase)
you'll do
const userWallet = ethers.HDNodeWallet.fromMnemonic(userWalletKeys.phrase)
You can also just import modularly like this:
const { HDNodeWallet } = require('ethers')
then use just use it without importing the entire ethers library, like this:
const userWallet = HDNodeWallet.fromMnemonic(userWalletKeys.phrase)
see docs here: ethers v6 docs
In v.6.1.0 you have to use ethers.Wallet.fromPhrase
Just been using ChatGPT to debug this very same error and after many twists and turns it suggested to fall back to ethers 5.0.0 (modifying package.json) and that worked. It seems in version 6.1.0 that method has dissappeared or maybe isn't ready yet or something...