What is a deterministic (HD) wallet and how does it work?

Covalent TeamUpdated 12 min read

A deterministic wallet derives every key from one seed, so a 12- or 24-word phrase backs up all of them. How HD wallets, BIP-32/39/44, paths and xpubs work.

A deterministic wallet derives all of its private keys from a single random seed, so one backup, usually a 12- or 24-word recovery phrase, restores every key and address it will ever create. A hierarchical deterministic (HD) wallet, defined in BIP-32, arranges those keys in a tree: accounts, receive and change chains, and addresses, each found by a derivation path such as m/84'/0'/0'/0/0. Almost every Bitcoin and Ethereum wallet today is an HD wallet.

What a deterministic wallet is

The earliest Bitcoin wallets were non-deterministic: they generated each private key at random and kept a pool of them. Every new key needed a new backup, so an old backup could miss coins sent to keys made after it. Bitcoin Core worked this way until version 0.13 added HD wallets in 2016.

A deterministic wallet fixes that by computing keys instead of drawing them. The same seed run through the same algorithm always gives the same keys, in the same order. Back up the seed once and you can rebuild the wallet on any compatible software, years later.

There are two kinds:

  • Sequential deterministic wallets derive a flat list of keys from the seed, one after another. Early Electrum versions worked this way.
  • Hierarchical deterministic wallets derive a tree. Any key can have its own children, so one seed can hold separate accounts, coins and purposes. HD wallets also have extended public keys (xpubs), which let a server or an accountant see every address in an account without being able to spend.
Non-deterministic (random keys) HD wallet
Where keys come from A random number generator, each time One seed, through BIP-32
Backup Every key, again after each new one The seed (recovery phrase), once
New address per payment Grows the backup Free: derive the next index
Watch-only access Export every public key Share one xpub
Standards None BIP-32, BIP-39, BIP-44 and the BIPs built on it

How an HD wallet works

An HD wallet goes from a phrase to an address in four steps. Each is set out in a Bitcoin Improvement Proposal, which is why one phrase works across wallets.

1. Entropy becomes a recovery phrase (BIP-39). The wallet draws 128 to 256 bits of randomness, appends a checksum (the first bits of its SHA-256 hash) and splits the result into 11-bit groups. Each group picks a word from a fixed list of 2,048 words. 128 bits gives 12 words and 256 bits gives 24. The checksum is why a mistyped or invented phrase is rejected: a phrase you make up yourself is almost never valid. See BIP-39.

2. The phrase becomes a seed (BIP-39). The words, with an optional passphrase, go through PBKDF2 with HMAC-SHA512 and 2,048 iterations, giving a 512-bit seed. A different passphrase gives a different seed, and so a completely different wallet.

3. The seed becomes a master key (BIP-32). HMAC-SHA512, keyed with the string Bitcoin seed, turns the seed into 512 bits. The left 256 bits are the master private key and the right 256 bits the master chain code. A key together with its chain code is an extended key.

4. Keys derive children (BIP-32). From an extended key and an index, BIP-32 computes a child extended key, and from that its children, as deep as you like. Each key has 2^31 normal children (indexes 0 to 2^31 − 1) and 2^31 hardened children (2^31 and up, written with an apostrophe or h: 0' is index 2^31):

  • A normal child's public key can be computed from the parent's public key alone. That is what makes watch-only xpubs possible.
  • A hardened child needs the parent's private key. It exists for safety: anyone with an xpub and any one normal child private key below it can work out the xpub's private key, and with it every key underneath. Hardened levels stop that leak from climbing higher in the tree.

The address at the end comes from the leaf public key, encoded for the script type (legacy, SegWit or Taproot) the path calls for.

Derivation paths: BIP-44, BIP-49, BIP-84 and BIP-86

A derivation path names one key in the tree. BIP-44, building on the purpose field of BIP-43, fixed five levels that nearly every wallet now follows:

m / purpose' / coin_type' / account' / change / address_indexm / 84'      / 0'         / 0'       / 0      / 0
  • m is the master key.
  • purpose' says which standard, and so which address type, the branch uses.
  • coin_type' is the coin, from the SLIP-44 registry: 0' for Bitcoin, 1' for every testnet, 60' for Ethereum.
  • account' separates accounts within one seed, like separate bank accounts.
  • change is 0 for receiving addresses you hand out and 1 for change addresses the wallet pays back to itself.
  • address_index counts up from 0, one new address per payment.

The first three levels are hardened; the last two are normal, so an account-level xpub can derive every receive and change address. When a wallet restores from a phrase, it scans addresses in order and stops after 20 unused ones in a row, the gap limit in BIP-44.

The purpose number also sets the address type. These are the four in common use for Bitcoin:

Standard Path Address type Addresses start Extended public key
BIP-44 m/44'/0'/0'/0/i Legacy (P2PKH) 1… xpub
BIP-49 m/49'/0'/0'/0/i Nested SegWit (P2WPKH in P2SH) 3… ypub
BIP-84 m/84'/0'/0'/0/i Native SegWit (P2WPKH) bc1q… zpub
BIP-86 m/86'/0'/0'/0/i Taproot (P2TR, single key) bc1p… xpub

So one recovery phrase holds four separate Bitcoin wallets. If a restored wallet shows a zero balance, it is often looking at the wrong path: coins received on bc1q… addresses sit under m/84', not m/44'. On Ethereum, wallets such as MetaMask use m/44'/60'/0'/0/i, and the address comes from the Keccak-256 hash of the public key instead.

Extended keys: xpub, ypub and zpub

An extended key is a key plus its chain code, serialized in 78 bytes (version, depth, parent fingerprint, child index, chain code and key) and encoded in Base58Check, so it is 111 characters long. The version bytes set the first four letters:

  • xprv / xpub: the BIP-32 default, used for BIP-44 legacy and for BIP-86 Taproot.
  • yprv / ypub: BIP-49 nested SegWit.
  • zprv / zpub: BIP-84 native SegWit.

The prefix tells software which address type to derive, since the key bytes alone don't say. SLIP-132 lists the registered prefixes. Newer software such as Bitcoin Core describes the same thing with output descriptors, for example wpkh([fingerprint/84h/0h/0h]xpub…/0/*), instead of a prefix.

An account-level xpub (or ypub or zpub) is the key you hand to watch-only software. It derives every public key and address in the account, so it can show balances and generate fresh receive addresses, but it can't sign. An xprv can spend everything beneath it, so treat it like the recovery phrase.

Derive HD wallet addresses in code

This derives the account key and first receive address for all four Bitcoin standards from one recovery phrase. It uses the audited @scure and @noble libraries:

npm install @scure/bip39@1.6.0 @scure/bip32@1.7.0 @scure/base@1.2.6 @noble/hashes@1.8.0 @noble/curves@1.9.1

The phrase is the test vector from BIP-84 and BIP-86. It is public, and its addresses are watched by bots, so never send real funds to it.

// derive.mjsimport { schnorr, secp256k1 } from "@noble/curves/secp256k1";import { ripemd160 } from "@noble/hashes/legacy";import { sha256 } from "@noble/hashes/sha2";import { bech32, bech32m, createBase58check } from "@scure/base";import { HDKey } from "@scure/bip32";import { mnemonicToSeedSync, validateMnemonic } from "@scure/bip39";import { wordlist } from "@scure/bip39/wordlists/english"; // The BIP-84 / BIP-86 test-vector phrase. Public: never send real funds to it.const MNEMONIC = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"; const base58check = createBase58check(sha256);const hash160 = (bytes) => ripemd160(sha256(bytes));const concat = (...parts) => Uint8Array.from(parts.flatMap((p) => [...p])); // Version bytes for each extended key prefix (BIP-32, BIP-49, BIP-84).const XPUB = { private: 0x0488ade4, public: 0x0488b21e };const YPUB = { private: 0x049d7878, public: 0x049d7cb2 };const ZPUB = { private: 0x04b2430c, public: 0x04b24746 }; // Encode a 33-byte compressed public key as each address type.const encode = {    p2pkh: (pub) => base58check.encode(concat([0x00], hash160(pub))),    "p2sh-p2wpkh": (pub) => base58check.encode(concat([0x05], hash160(concat([0x00, 0x14], hash160(pub))))),    p2wpkh: (pub) => bech32.encode("bc", [0, ...bech32.toWords(hash160(pub))]),    p2tr: (pub) => {        // BIP-86: tweak the x-only key with no script tree (BIP-341), then encode with bech32m.        const x = pub.slice(1);        const t = schnorr.utils.taggedHash("TapTweak", x);        const P = schnorr.utils.lift_x(schnorr.utils.bytesToNumberBE(x));        const Q = P.add(secp256k1.ProjectivePoint.BASE.multiply(schnorr.utils.bytesToNumberBE(t)));        return bech32m.encode("bc", [1, ...bech32m.toWords(schnorr.utils.pointToBytes(Q))]);    },}; const SCHEMES = [    { bip: 44, account: "m/44'/0'/0'", versions: XPUB, script: "p2pkh" },    { bip: 49, account: "m/49'/0'/0'", versions: YPUB, script: "p2sh-p2wpkh" },    { bip: 84, account: "m/84'/0'/0'", versions: ZPUB, script: "p2wpkh" },    { bip: 86, account: "m/86'/0'/0'", versions: XPUB, script: "p2tr" },]; if (!validateMnemonic(MNEMONIC, wordlist)) throw new Error("Invalid recovery phrase (bad checksum)");const seed = mnemonicToSeedSync(MNEMONIC, ""); // BIP-39: PBKDF2-HMAC-SHA512, 2,048 rounds, no passphrase for (const { bip, account, versions, script } of SCHEMES) {    const acct = HDKey.fromMasterSeed(seed, versions).derive(account);    const first = acct.deriveChild(0).deriveChild(0); // .../0/0: first receive address    console.log(`BIP-${bip} ${account}/0/0`);    console.log(`  account key: ${acct.publicExtendedKey}`);    console.log(`  address:     ${encode[script](first.publicKey)}`);}

Running node derive.mjs prints:

BIP-44 m/44'/0'/0'/0/0  account key: xpub6BosfCnifzxcFwrSzQiqu2DBVTshkCXacvNsWGYJVVhhawA7d4R5WSWGFNbi8Aw6ZRc1brxMyWMzG3DSSSSoekkudhUd9yLb6qx39T9nMdj  address:     1LqBGSKuX5yYUonjxT5qGfpUsXKYYWeabABIP-49 m/49'/0'/0'/0/0  account key: ypub6Ww3ibxVfGzLrAH1PNcjyAWenMTbbAosGNB6VvmSEgytSER9azLDWCxoJwW7Ke7icmizBMXrzBx9979FfaHxHcrArf3zbeJJJUZPf663zsP  address:     37VucYSaXLCAsxYyAPfbSi9eh4iEcbShgfBIP-84 m/84'/0'/0'/0/0  account key: zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs  address:     bc1qcr8te4kr609gcawutmrza0j4xv80jy8z306fyuBIP-86 m/86'/0'/0'/0/0  account key: xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ  address:     bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr

The BIP-84 zpub and address and the BIP-86 xpub and address are exactly the test vectors published in those BIPs, which is the quickest way to check your own derivation code.

A watch-only service never sees the phrase. Given only the zpub, this addition to derive.mjs derives the same receive addresses, because the last two levels are normal (not hardened):

// Receive addresses from an account zpub alone: no private key involved.function receiveAddresses(zpub, count) {    const account = HDKey.fromExtendedKey(zpub, ZPUB);    return Array.from({ length: count }, (_, i) => encode.p2wpkh(account.deriveChild(0).deriveChild(i).publicKey));} const zpub =    "zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs";console.log(receiveAddresses(zpub, 3));// [ 'bc1qcr8te4kr609gcawutmrza0j4xv80jy8z306fyu',//   'bc1qnjg0jd8228aq7egyzacy8cys3knf9xvrerkf9g',//   'bc1qp59yckz4ae5c4efgw2s5wfyvrz0ala7rgvuz8z' ]

Look up an HD wallet's balances by xpub

Deriving addresses is the easy half. To show an HD wallet's balance you also need to know which of its addresses have been used and what each holds, which means scanning the chain. The Bitcoin xpub API in GoldRush does that scan: give it an xpub, ypub or zpub and it returns every active address derived from it, with its balance. It runs on btc-mainnet (chain ID 20090103) and its credit cost is 0.1 per item, where an item is one address returned.

const API = "https://api.covalenthq.com/v1"; // Every active address behind an extended public key, with its balance in satoshis.async function getHdWallet(xpub) {    const res = await fetch(`${API}/btc-mainnet/address/${xpub}/hd_wallets/`, {        headers: { Authorization: `Bearer ${process.env.GOLDRUSH_API_KEY}` },    });    if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);    const { data } = await res.json();    const sats = data.items.reduce((sum, item) => sum + BigInt(item.balance), 0n);    return {        asOfBlock: data.chain_tip_height,        totalSats: sats.toString(),        addresses: data.items.map((item) => ({            address: item.child_address,            path: item.address_path,            sats: item.balance,            lastActive: item.last_transferred_at,        })),    };} const wallet = await getHdWallet(    "zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs");console.table(wallet.addresses);

For the test wallet's BIP-84 zpub it returned 11 addresses on 20 November 2026, at block 976,707, all empty. Three of them, abridged:

[    {        "child_address": "bc1qcr8te4kr609gcawutmrza0j4xv80jy8z306fyu",        "address_path": "M/0H/0/0",        "last_transferred_at": "2026-10-21T15:40:38Z",        "balance": "0",        "quote": 0    },    {        "child_address": "17ZDsck7dRdhVvnYfANNnSv522xhsDPJMd",        "address_path": "M/0H/0/3",        "last_transferred_at": "2026-01-10T22:45:56Z",        "balance": "0",        "quote": 0    },    {        "child_address": "bc1qgl5vlg0zdl7yvprgxj9fevsc6q6x5dmcyk3cn3",        "address_path": "M/0H/0/3",        "last_transferred_at": "2020-12-25T11:03:24Z",        "balance": "0",        "quote": 0    }]
  • child_address at M/0H/0/0 is the same bc1qcr8te… address the code above derived; every address in the response matches a local derivation from the zpub.
  • The last two numbers of address_path are the chain (0 for receive) and the index. Index 3 appears twice because both its native SegWit address and the legacy 1… address of the same public key have been used.
  • balance is in satoshis, as a string (1 BTC = 100,000,000 sats). The 11 addresses cost 1.1 credits.

An HD wallet's balance is the sum over its addresses. For per-address transaction history and the other Bitcoin endpoints, see the Bitcoin wallet lookup and transaction tracking guide and the Bitcoin API overview.

Keeping an HD wallet safe

  • The recovery phrase is the wallet. Anyone who has it can spend every coin on every path. Write it down on paper or stamp it in metal, keep it offline, and never type it into a website, a chat or a cloud note. Hardware wallets generate and keep the phrase on the device so it never touches an online computer.
  • A passphrase adds a second factor, and a second risk. BIP-39's optional passphrase turns the same 12 words into a different wallet. Someone who finds the words can't see the funds, but if you forget the passphrase there is no reset: a wrong passphrase simply opens a different, empty wallet.
  • An xpub is private, even though it can't spend. It reveals every past and future address in the account and so the whole balance and payment history. Share it only with software you trust, and treat your users' xpubs as personal data.
  • Never let a normal child private key and its xpub meet. Together they give away the account's private key and every key under it (BIP-32, "Security"). This is why account levels are hardened and why you should never export a single address's private key from a wallet whose xpub is shared.
  • Record the path and script type with the backup. Most wallets follow BIP-44/49/84/86, but noting which one (or keeping the output descriptor) saves a search through four paths when you restore.

Frequently asked questions

What is a deterministic wallet?

A deterministic wallet derives all of its keys from one random seed with a fixed algorithm, so the same seed always produces the same keys. Backing up the seed, usually as a 12- or 24-word recovery phrase, backs up every key the wallet has made or will make.

What is the difference between a deterministic wallet and an HD wallet?

An HD (hierarchical deterministic) wallet is a deterministic wallet whose keys form a tree, as defined in BIP-32. Any key can derive children, so one seed holds separate accounts, coins and receive and change chains, and an extended public key (xpub) can derive every address in a branch without the private keys. Almost all deterministic wallets today are HD wallets.

What do BIP-32, BIP-39 and BIP-44 each do?

BIP-39 turns random entropy into a recovery phrase and the phrase into a 512-bit seed. BIP-32 turns that seed into a master key and defines how child keys, extended keys and hardened keys are derived. BIP-44 fixes the derivation path layout, m/purpose'/coin_type'/account'/change/address_index, so wallets find the same addresses from the same phrase. BIP-49, BIP-84 and BIP-86 reuse that layout for nested SegWit, native SegWit and Taproot addresses.

What is the difference between an xpub, a ypub and a zpub?

They are the same kind of key, an account-level extended public key, with different version bytes. The prefix tells software which addresses to derive: xpub for legacy 1… addresses (BIP-44) and Taproot bc1p… addresses (BIP-86), ypub for nested SegWit 3… addresses (BIP-49) and zpub for native SegWit bc1q… addresses (BIP-84).

Why does my restored wallet show a different address or a zero balance?

The new wallet is most likely deriving a different path or address type, for example m/44' legacy addresses when your coins are on m/84' native SegWit ones, or it was restored without the BIP-39 passphrase you used, which opens a different wallet. Choose the matching script type or path in the wallet's restore options, and enter the passphrase if you set one.

Can I check an HD wallet's balance from its xpub?

Yes. An xpub, ypub or zpub derives every address in the account, so software can scan them without any private key. The GoldRush HD wallet balances endpoint does this for Bitcoin: it returns each active address behind the key with its balance, and the wallet's balance is their sum.

Next steps

Get new guides by email

New tutorials and best practices for building with blockchain data, sent as they're published.