javascript TypeError:助记符.computeSeed不是函数

cyej8jka  于 11个月前  发布在  Java
关注(0)|答案(1)|浏览(83)

这是我的代码(https://i.stack.imgur.com/eCKGy.png),这是我的错误(https://i.stack.imgur.com/MLWUg.png
我尝试从HDNodeWallet更改为HDNode,但仍然没有结果(https://i.stack.imgur.com/7HZv4.png)这是我尝试从HDNodeWallet更改为HDNode时收到的结果

kpbpu008

kpbpu0081#

我认为你应该回到一个旧版本的以太图书馆。我想。在我自己的情况下,我使用的版本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]

可能不是最终的解决方案,但它的工作

相关问题