HD Wallet Generator

3.6.1 · active · verified Fri Apr 17

hdwallet is a Python library that implements a Hierarchical Deterministic (HD) Wallet generator, supporting over 200 cryptocurrencies. It is currently at version 3.6.1 and sees active development with minor releases every few weeks to months, typically adding new cryptocurrencies, enhancements, and bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to generate a new 12-word BIP-39 mnemonic, derive an Ethereum address using a standard BIP-44 path, and retrieve its associated private and public keys. It highlights the use of `generate_mnemonic`, `is_mnemonic_valid`, `HDWallet`, `from_mnemonic`, and `from_path`.

from hdwallet import HDWallet
from hdwallet.symbols import ETH as SYMBOL
from hdwallet.derivations import BIP44Derivation
from hdwallet.utils import generate_mnemonic, is_mnemonic_valid

# 1. Generate a new mnemonic phrase (12 words)
mnemonic = generate_mnemonic(language="english", strength=128)

# 2. Optionally, validate the mnemonic
if not is_mnemonic_valid(mnemonic, language="english"):
    raise ValueError("Invalid mnemonic phrase")

# 3. Create an HDWallet instance
hdwallet = HDWallet(symbol=SYMBOL)

# 4. From mnemonic, get the root key
hdwallet.from_mnemonic(mnemonic=mnemonic, language="english", passphrase=None)

# 5. Derive a child key using a BIP44 path for Ethereum
# Example: m/44'/60'/0'/0/0
hdwallet.from_path(path=BIP44Derivation.m / BIP44Derivation.coin_types.ETH / BIP44Derivation.PURPOSE.root / BIP44Derivation.ACCOUNT.root / BIP44Derivation.CHANGE.root / BIP44Derivation.ADDRESS.root)

# 6. Get wallet details
print(f"Mnemonic: {hdwallet.mnemonic()}")
print(f"Base HD path: {hdwallet.base_hd_path()}")
print(f"Address: {hdwallet.address()}")
print(f"Private Key: {hdwallet.private_key()}")
print(f"Public Key: {hdwallet.public_key()}")

view raw JSON →