我认为你应该恢复到旧版本的以太库。我认为。就我自己而言,我使用的是 5.7.2 版本并且它有效。 这是我的代码
const ethers = require('ethers');
// Generate a random mnemonic (12-word phrase)
const mnemonic = ethers.Wallet.createRandom().mnemonic.phrase;
// Create a wallet from the mnemonic
const wallet = ethers.Wallet.fromMnemonic(mnemonic);
// Retrieve the private key
const privateKey = wallet.privateKey;
// Retrieve the public key
const publicKey = wallet.address;
console.log('Mnemonic:', mnemonic);
console.log('Private Key:', privateKey);
console.log('Public Key (Address):', publicKey);
我遇到的错误是这样的
const wallet = ethers.Wallet.fromMnemonic(mnemonic);
^
TypeError: ethers.Wallet.fromMnemonic is not a function
直到我恢复到5.7.2版本
npm i [email protected]
可能不是最终的解决方案,但它有效