类型错误:mnemonic.computeSeed 不是函数

问题描述 投票:0回答:1

这是我的代码 (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 时收到的结果

javascript web3js ethers.js
1个回答
0
投票

我认为你应该恢复到旧版本的以太库。我认为。就我自己而言,我使用的是 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]       

可能不是最终的解决方案,但它有效

© www.soinside.com 2019 - 2024. All rights reserved.