Book a free call

Bitcoin Wallet Libraries and APIs: What to Use

A Bitcoin wallet needs key generation, address handling, UTXO tracking and signing. These libraries and APIs cover each part, so you build less from scratch.

Hertiv engineering teamReviewed by a senior engineer
7 min read
Bitcoin Wallet Libraries and APIs: What to Use
On this page

Short answer

A Bitcoin wallet is built from a few parts: key generation and derivation, address handling, UTXO tracking, fee estimation and transaction signing. Libraries such as Bitcoin Dev Kit and bitcoinjs-lib cover the wallet logic, while APIs such as mempool.space and Blockstream Esplora supply chain data. You still need your own backup, recovery and audit work; no library removes that.

What does a Bitcoin wallet need to do?

A Bitcoin wallet is software that creates and guards private keys, builds and signs transactions, and talks to the Bitcoin network so a user can check a balance and send or receive funds. The coins never sit in the app; they live on the blockchain as unspent outputs, and the wallet holds the keys that prove ownership of them.

Every wallet, from a simple phone app to a business treasury tool, does the same five jobs: generate keys, derive addresses, track unspent outputs, estimate fees, and sign transactions. The libraries and APIs below each cover one or more of these jobs, and choosing them well is most of the technical work in a wallet project. For the full project, from team to launch, see how to develop a Bitcoin wallet app.

JobWhat it doesCovered by
Key generationBIP39 phrase, BIP32 derivationBDK, bitcoinjs-lib
Address handlingSegWit and Taproot addressesBDK, bitcoinjs-lib
UTXO trackingBalance and spendable outputsEsplora, mempool API
Fee estimationCurrent fee ratesmempool API
SigningPrivate key signs, never leaves deviceBDK, bitcoinjs-lib

Which libraries build the wallet itself?

The wallet logic lives in a library that handles keys, addresses and transactions. The two most widely used choices are Bitcoin Dev Kit and bitcoinjs-lib, and the right one depends on your language and how much control you need.

Bitcoin Dev Kit, known as BDK, is a modular Rust library for building Bitcoin wallets. It is descriptor-based, so the same code can build a single-signature wallet, a multisignature wallet or a timelocked contract, and it supports several blockchain backends and databases. BDK Wallet 1.0 was released in December 2024 with a stable API, and it is used in wallets such as Bitkey and ProtonWallet.

bitcoinjs-lib is a JavaScript and TypeScript library for Node.js and browsers. It creates, signs and manages Bitcoin transactions and addresses, including legacy, SegWit and Taproot formats, and works with companion libraries for mnemonics (BIP39) and key derivation (BIP32). It suits teams that want low-level control over transactions, such as multisignature wallets and time-locked spending conditions.

Two other libraries are worth knowing. rust-bitcoin is a lower-level Rust toolkit for Bitcoin software, and libwally-core is a C library with bindings for several languages that covers keys, addresses and transactions. Both are used inside larger wallet projects rather than as a full wallet kit.

Which APIs supply chain data?

A wallet needs chain data: balances, transaction history, fee rates and the current block height. Most wallets get this from an API or a node, not by reading the blockchain directly, because running a full node is heavy for a phone app.

The mempool.space API is the most common choice for fee rates and transaction data, with a public service and a self-hosted option. Blockstream Esplora is an open-source explorer and API that serves blocks, transactions and address history. The Electrum protocol is a third route: lightweight servers answer balance and history queries without the wallet running a node.

SourceWhat it givesTrade-off
Own Bitcoin Core nodeFull verification, no third partyNeeds disk space and sync time
mempool.space APIFees, transactions, blocksTrusts the provider
Blockstream EsploraAddress history, blocksTrusts the provider
Electrum serverFast balance and historyTrusts the server

Whichever source you choose, treat it as untrusted for balances that matter. A wallet that checks the same address against two sources catches a lying server, and a wallet that verifies transactions against its own rules does not need to trust the API at all.

How do the parts fit together?

The parts fit together in a short flow. Keys are generated once, addresses are derived from them, the API reports which outputs belong to those addresses, the wallet builds a transaction from those outputs, and the library signs it before broadcast. Each step uses a different tool, and the handoff between steps is where most wallet bugs live.

  1. Generate the seed. BDK or bitcoinjs-lib creates a BIP39 phrase and derives keys with BIP32.
  2. Derive addresses. The library produces SegWit or Taproot addresses for receiving.
  3. Sync the balance. Esplora, mempool.space or an Electrum server reports the unspent outputs for those addresses.
  4. Build the transaction. The library selects outputs, adds the recipient and estimates the fee.
  5. Sign and broadcast. The private key signs on the device, and the signed transaction goes to the network through the API or a node.

The signing step is the security boundary. Keys should be generated on the device, encrypted with a key from the user's passcode or biometrics, and stored in the operating system's secure storage. The server should never see a private key or a recovery phrase. See how to secure a crypto wallet for the checks a user should run on any wallet.

How do you choose a library and an API, step by step?

You choose by language, control and trust, in that order. A library that fits your stack and a data source you can verify will save more time than the newest option.

  1. Pick the language first. Rust teams usually start with BDK; JavaScript and TypeScript teams usually start with bitcoinjs-lib.
  2. Decide how much control you need. BDK covers the wallet flow end to end; bitcoinjs-lib gives lower-level control over transactions and scripts.
  3. Choose the data source. Start with a public API for a prototype, then move to your own node or a second source for production.
  4. Plan the backup. Confirm the recovery phrase flow and the lost-device case before you write the send screen.
  5. Test on testnet. Run the whole flow with coins that have no value, including a restore from the recovery phrase.
  6. Get an audit. An independent review of the key handling and signing code is part of the build, not an extra.

A partner for crypto wallet development can help with the parts that need review, such as the signing path and the backup flow, once the libraries are chosen.

Example (hypothetical): sending half a bitcoin

Example (hypothetical): a wallet holds three unspent outputs worth 0.4, 0.3 and 0.3 BTC, a total of 1.0 BTC. The user wants to send 0.5 BTC to a friend.

The wallet picks the 0.4 and 0.3 outputs, a total of 0.7 BTC, because the smallest single output does not cover the payment. It builds a transaction with two inputs: 0.5 BTC to the friend, a fee of 0.0002 BTC, and the rest back to the user as change. The change is 0.7 minus 0.5 minus 0.0002, which is 0.1998 BTC, and the third output of 0.3 BTC stays untouched.

The fee comes from the mempool API, which reports the current rate for the next block. If the rate rises before the user confirms, the wallet rebuilds the transaction with the new fee and the change falls by the same amount. The user sees the fee, the destination and the amount on one screen before confirming.

What should you not build yourself?

You should not build your own cryptography, random number generation or key derivation. Those parts have been written, reviewed and attacked for years, and a small mistake in them loses money that cannot be recovered. Use a vetted library and let an audit check how you use it.

You should not build your own fee estimator from scratch either. Fee markets move quickly, and an estimator that reads stale data leaves transactions stuck or overpays. Use the mempool API or an Esplora instance, and test the estimator against real network conditions.

You should not invent a backup scheme. A 12 or 24 word recovery phrase, shown once and confirmed word by word, is the standard because users and support teams understand it. A custom scheme that users cannot explain to support is a scheme that will strand funds.

What are the common mistakes?

The most common wallet library mistakes are picking a library for its name rather than its fit, trusting one API for balances, and shipping without an audit.

  • Choosing by popularity. A library that fits another team's stack may not fit yours. Check the language, the address types and the signing model first.
  • Trusting one data source. A single API can be down, slow or wrong. Check critical balances against a second source.
  • Storing keys in plain text. Keys in plain text on the device or sent to a server are already compromised. Use secure storage and encrypt with the passcode.
  • Skipping testnet. A wallet tested only on the happy path will fail on a lost device, a wrong address or a fee spike.
  • Hiding the fee. A wallet that does not show the fee before the user confirms will generate angry support tickets the first time the network is busy.

Key takeaways

  • A wallet does five jobs: keys, addresses, UTXO tracking, fees and signing
  • BDK suits Rust teams; bitcoinjs-lib suits JavaScript and TypeScript teams
  • mempool.space, Esplora and Electrum servers supply chain data without a full node
  • Signing is the security boundary: keys never leave the device
  • Test on testnet and audit the signing path before launch

Frequently asked questions

What is Bitcoin Dev Kit?

Bitcoin Dev Kit, or BDK, is a modular Rust library for building Bitcoin wallets. It is descriptor-based, so the same code can build single-signature, multisignature and timelocked wallets. BDK Wallet 1.0 was released in December 2024 with a stable API.

What is bitcoinjs-lib?

bitcoinjs-lib is a JavaScript and TypeScript library for Bitcoin transactions and addresses. It supports legacy, SegWit and Taproot formats, works with BIP39 and BIP32 companion libraries, and suits teams that want low-level control over transactions and scripts.

Do I need to run my own Bitcoin node for a wallet?

No, but it is the most private and most verifiable option. Most wallets start with a public API such as mempool.space or Esplora, then move to their own node or a second source for production, so a single provider cannot lie about a balance.

What is a UTXO, and why does a wallet track them?

A UTXO is an unspent transaction output: a chunk of bitcoin that has not been spent yet. A wallet balance is the sum of its UTXOs, and sending bitcoin means picking UTXOs, spending them, and returning the change. Tracking them is how the wallet knows what it can spend.

Can I use the same library for Lightning wallets?

Not directly. BDK and bitcoinjs-lib cover on-chain wallets. Lightning needs a different stack, such as the Lightning Development Kit for channels and payments. Some wallets combine both, with on-chain code for funding and Lightning code for payments.

How do I keep a wallet's keys safe?

Generate keys on the device, encrypt them with a key from the user's passcode or biometrics, and store them in the operating system's secure storage. Never send a private key or recovery phrase to a server, and confirm the recovery phrase before the user deposits funds.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: blockchain systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Planning a Bitcoin wallet? Talk to Hertiv.

A senior engineer replies within one business day. Or see our Crypto Wallet service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to contact@hertiv.com.

Prefer email? Write to contact@hertiv.com
Estimate costBook a call