HDNode provides BIP32 Hierarchical Deterministic wallet functionality for Ethereum and other cryptocurrencies. It enables deterministic key pair generation from mnemonic phrases, hierarchical key derivation using standard paths, and comprehensive wallet management with full BIP39/BIP32 compliance.
npm install @ethersproject/hdnodeimport { HDNode, mnemonicToSeed, defaultPath, type Mnemonic } from "@ethersproject/hdnode";
import { Wordlist } from "@ethersproject/wordlists";
import { BytesLike } from "@ethersproject/bytes";For CommonJS:
const { HDNode, mnemonicToSeed, defaultPath } = require("@ethersproject/hdnode");import { HDNode, mnemonicToSeed, isValidMnemonic } from "@ethersproject/hdnode";
// Create HDNode from mnemonic
const mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
const rootNode = HDNode.fromMnemonic(mnemonic);
// Derive child keys using BIP44 paths
const accountNode = rootNode.derivePath("m/44'/60'/0'/0/0");
console.log("Address:", accountNode.address);
console.log("Private Key:", accountNode.privateKey);
// Validate mnemonic phrases
const isValid = isValidMnemonic(mnemonic);
console.log("Valid mnemonic:", isValid);
// Convert mnemonic to seed
const seed = mnemonicToSeed(mnemonic, "optional-password");
console.log("Seed:", seed);The HDNode package is structured around several key components:
Core hierarchical deterministic node functionality for key derivation, wallet management, and extended key operations.
class HDNode {
readonly privateKey: string | null;
readonly publicKey: string;
readonly address: string;
readonly mnemonic?: Mnemonic;
readonly path: string;
static fromMnemonic(mnemonic: string, password?: string, wordlist?: string | Wordlist): HDNode;
static fromSeed(seed: BytesLike): HDNode;
static fromExtendedKey(extendedKey: string): HDNode;
derivePath(path: string): HDNode;
neuter(): HDNode;
get extendedKey(): string;
}BIP39 mnemonic phrase operations including generation, validation, and conversion between mnemonic phrases, entropy, and seeds.
function mnemonicToSeed(mnemonic: string, password?: string): string;
function mnemonicToEntropy(mnemonic: string, wordlist?: string | Wordlist): string;
function entropyToMnemonic(entropy: BytesLike, wordlist?: string | Wordlist): string;
function isValidMnemonic(mnemonic: string, wordlist?: Wordlist): boolean;Helper functions for path generation and common operations.
const defaultPath: string; // "m/44'/60'/0'/0/0"
function getAccountPath(index: number): string;interface Mnemonic {
readonly phrase: string;
readonly path: string;
readonly locale: string;
}