Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Wallet development

Wallet development

What are a wallet’s functions?

  • Key management
    • Identify owned transactions
    • Generating new addresses
    • Determining how to sign transactions
  • Constructing and sending transactions
    • Parsing addresses and turning them into txOuts
    • Selecting UTXOs (coin selection)
    • Signing inputs
  • Persistence
    • Storing keys
    • Storing UTXOs
    • Storing transaction history
    • Storing metadata (eg how far through the blockchain have I parsed?)


Initialization and Interfaces

Why all this indirection?

To fully separate the wallet from the node:

  • Well defined interface is easier to reason about
  • Individual components can be tested in isolation
  • Separate wallet into a different process
  • Potential for different wallet implementations

Code Management

  • coinselection.cpp|h - Coin selection algorithm
  • crytper.cpp|h - encrypting the wallet’s private keys
  • [wallet]db.cpp|h - interface to wallet’s database for persistent storage
  • init.cpp - initializing the wallet module
  • load.cpp|h - loading/starting/stopping individual wallets
  • rpc.cpp|h* - wallet’s RPC interface
  • wallettool.cpp|h - standalone wallet tool binary
  • wallet.cpp|h - EVERYTHING ELSE

Key Management

Identify Owned Transactions

Generating Addresses

  • The Bitcoin Core wallet was originally a collection of unrelated private keys
  • If a new address was required, a new private key could be generated
  • What are the problems with this?
  • Giving an address out and then restoring from a backup loses funds!


HD Wallets

Generating Keys


Constructing and Sending Transactions

Parsing addresses and Constructing Transactions

Selecting UTXOs (coin selection)

Signing inputs

Sending Transactions


Future Directions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment