Understanding HD Wallets: From BIP32, BIP39, BIP44 to Ethereum

·

A cryptocurrency wallet is often the first point of contact for anyone entering the world of Ethereum or other digital assets. Whether using a mobile or browser-based wallet, many users encounter a unique set of words that must be securely backed up. This system originates from Bitcoin's wallet design, and wallets implementing this mechanism are commonly known as HD Wallets (Hierarchical Deterministic Wallets). This article explains the architecture of HD Wallets and demonstrates how to create an Ethereum HD Wallet using JavaScript libraries.

What Is a Cryptocurrency Wallet?

A wallet typically stores value. In the cryptocurrency world, however, the situation is different. Your account information—such as your balance—is stored on the blockchain. What actually resides in your wallet is the cryptographic key associated with your account. Possessing this key allows you to prove your identity in the crypto world and modify your account state, such as sending funds to others. Thus, a cryptocurrency wallet is essentially a tool for managing and storing cryptographic keys. This key is your private key, and your account is derived from the corresponding public key.

Core Standards: BIP32, BIP39, and BIP44

BIP stands for Bitcoin Improvement Proposal. These documents propose new features or improvements for Bitcoin and can be submitted by anyone. After review, they are published on GitHub. The relationship between BIPs and Bitcoin is similar to that between RFCs and the Internet.

Together, BIP32, BIP39, and BIP44 define the widely used HD Wallet standard, covering design motivations, implementation methods, and practical examples.

BIP32: Hierarchical Deterministic Wallets

BIP32 defines a system that generates a tree-like structure to store multiple key pairs (private and public keys) from a single seed. Benefits include easy backup, transfer between compatible devices (since only the seed is needed), and hierarchical permission controls.

BIP39: Mnemonic Code Phrases

BIP39 represents the seed using a series of easy-to-remember and write words. Typically, this consists of 12 words, known as a mnemonic code phrase (or seed phrase). For example:

rose rocket invest real refuse margin festival danger anger border idle brown

BIP44: Multi-Account and Multi-Currency Support

BIP44 builds on BIP32 by assigning specific meanings to each level in the hierarchical tree. This allows a single seed to support multiple currencies and accounts. The path structure is defined as:

m / purpose' / coin_type' / account' / change / address_index

Here, purpose' is fixed as 44' to indicate BIP44 compliance. The coin_type' denotes different cryptocurrencies—for example, Bitcoin is 0', and Ethereum is 60'.

Ethereum HD Wallet Implementation

Ethereum wallets adopt the Bitcoin HD Wallet framework, setting coin_type' to 60'. This was discussed in Ethereum’s EIPs issues. For instance, in an Ethereum HD Wallet, the first account (per BIP44's account' level) and its first key pair would follow the path: m/44'/60'/0'/0/0.


Creating an Ethereum HD Wallet

To create an Ethereum HD Wallet, we use several JavaScript libraries:

Installing the Packages

Use npm to install the required packages:

npm install bip39 ethereumjs-wallet ethereumjs-util --save

Initialization

Import the modules into your project:

var bip39 = require('bip39')
var hdkey = require('ethereumjs-wallet/hdkey')
var util = require('ethereumjs-util')

Generating a Mnemonic Code

Create a random mnemonic phrase:

var mnemonic = bip39.generateMnemonic()

The output will resemble:

rose rocket invest real refuse margin festival danger anger border idle brown

Generating the HD Wallet

Convert the mnemonic phrase to a binary seed:

var seed = bip39.mnemonicToSeed(mnemonic)

Use the seed to generate the master key for the HD Wallet:

var hdWallet = hdkey.fromMasterSeed(seed)

Deriving the First Ethereum Address

Derive the key pair for the first account using the BIP44 path m/44'/60'/0'/0/0:

var key1 = hdWallet.derivePath("m/44'/60'/0'/0/0")

Generate the Ethereum address from the public key:

var address1 = util.pubToAddress(key1._hdkey._publicKey, true)

Apply EIP-55 checksum encoding to enhance address security and prevent errors:

address1 = util.toChecksumAddress(address1.toString('hex'))

The resulting address will look like:

0x685ce4CbDd5c19b64CA008cB85b83947e5318EFA

You can verify your results using tools like the Mnemonic Code Converter.


Using Your Ethereum HD Wallet

Safely store your mnemonic code to create a cold wallet (offline storage), which significantly enhances security. You can use the generated address to receive Ether or any ERC-20 tokens. To send funds, import the mnemonic into any Ethereum HD Wallet-compatible software, such as MyEtherWallet, MetaMask (browser), or imToken (mobile).

How Does MetaMask Store Mnemonic Codes?

Since possessing the mnemonic code allows generation of all keys in an HD Wallet—and thus control over all associated funds—its security is paramount. MetaMask, a popular browser wallet, stores an encrypted version of the mnemonic in the browser's Local Storage (a persistent local data area). Encryption relies on a user-defined password, set during initial import. Each time the wallet is reopened, the password is required for decryption. The decryption algorithm is open source, with a live demo available.

👉 Explore secure wallet development tools


Frequently Asked Questions

What is an HD Wallet?
An HD Wallet (Hierarchical Deterministic Wallet) generates a tree of key pairs from a single seed. This allows easy backup and management of multiple accounts and cryptocurrencies while only needing to safeguard the initial seed phrase.

Why is the mnemonic phrase so important?
The mnemonic phrase can regenerate all private keys in your wallet. Anyone with access to it can control all associated assets. It is the ultimate backup and must be stored securely offline.

Can the same seed phrase be used for different cryptocurrencies?
Yes, through standards like BIP44, a single seed can derive addresses for multiple cryptocurrencies (e.g., Bitcoin and Ethereum) using different coin_type values in the derivation path.

What is the purpose of the derivation path?
The derivation path (e.g., m/44'/60'/0'/0/0) specifies how keys are hierarchically generated from the seed. It ensures deterministic key generation for different accounts, currencies, and addresses.

Is it safe to generate a wallet using online tools?
While convenient, online tools pose risks if the seed phrase is exposed. For high-value assets, use offline, open-source tools and ensure your environment is secure.

How can I enhance the security of my HD Wallet?
Use a strong password for encryption, store the mnemonic phrase offline (e.g., on paper or metal), enable two-factor authentication where possible, and keep software updated.


References and Further Reading

Additional Ethereum JavaScript Libraries

This introduction provides a foundation for understanding and creating HD Wallets. For deeper cryptographic details, consult the official BIP documents and Ethereum resources.

👉 Get advanced wallet management methods