You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ethers 6.9.0中ethers.Wallet.fromMnemonic不存在,如何用助记词生成钱包?

Ethers 6.9.0 中通过助记词生成钱包的方法

在ethers v6版本中,Wallet.fromMnemonic方法已被废弃,取而代之的是HDNodeWallet.fromPhrase()方法,用于从助记词生成钱包实例。

基础用法示例

import { ethers } from "ethers";

// 替换为你的助记词
const mnemonicPhrase = "your mnemonic phrase here";

// 从助记词生成钱包
const wallet = ethers.HDNodeWallet.fromPhrase(mnemonicPhrase);

// 获取钱包核心信息
console.log("钱包地址:", wallet.address);
console.log("私钥:", wallet.privateKey);

指定自定义派生路径

如果需要使用默认路径(m/44'/60'/0'/0/0)以外的派生路径,可以传入第二个参数:

const customDerivationPath = "m/44'/60'/1'/0/0";
const walletWithCustomPath = ethers.HDNodeWallet.fromPhrase(mnemonicPhrase, customDerivationPath);

注意事项

生成的HDNodeWallet实例完全兼容原Wallet类的所有功能,包括签名交易、消息等,无需额外适配即可沿用之前的业务逻辑。

内容的提问来源于stack exchange,提问作者yngwiewylde

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 20:20:56