Reputation: 31
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.
Upvotes: 3
Views: 5097
Reputation: 31
In 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
Upvotes: 3
Reputation: 539
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
Upvotes: 2
Reputation: 1
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...
Upvotes: -1