- Preface
- Writing the Bitcoin Book
- Intended Audience
- Why Are There Bugs on the Cover?
- Conventions Used in This Book
- Code Examples
- Using Code Examples
- Bitcoin Addresses and Transactions in This Book
- O’Reilly Safari
- How to Contact Us
- Contacting the Author
- Acknowledgments
- Early Release Draft (GitHub Contributions)
- 1. Introduction
- What Is Bitcoin?
- History of Bitcoin
- Bitcoin Uses, Users, and Their Stories
- Getting Started
- Choosing a Bitcoin Wallet
- Quick Start
- Getting Your First Bitcoin
- Finding the Current Price of Bitcoin
- Sending and Receiving Bitcoin
- 2. How Bitcoin Works
- Transactions, Blocks, Mining, and the Blockchain
- Bitcoin Overview
- Buying a Cup of Coffee
- Bitcoin Transactions
- Transaction Inputs and Outputs
- Transaction Chains
- Making Change
- Common Transaction Forms
- Constructing a Transaction
- Getting the Right Inputs
- Creating the Outputs
- Adding the Transaction to the Ledger
- Bitcoin Mining
- Mining Transactions in Blocks
- Spending the Transaction
- 3. Bitcoin Core: The Reference Implementation
- Bitcoin Development Environment
- Compiling Bitcoin Core from the Source Code
- Selecting a Bitcoin Core Release
- Configuring the Bitcoin Core Build
- Building the Bitcoin Core Executables
- Running a Bitcoin Core Node
- Running Bitcoin Core for the First Time
- Configuring the Bitcoin Core Node
- Bitcoin Core Application Programming Interface (API)
- Getting Information on the Bitcoin Core Client Status
- Exploring and Decoding Transactions
- Exploring Blocks
- Using Bitcoin Core’s Programmatic Interface
- Alternative Clients, Libraries, and Toolkits
- C/C++
- JavaScript
- Java
- Python
- Ruby
- Go
- Rust
- C#
- Objective-C
- 4. Keys, Addresses
- Introduction
- Public Key Cryptography and Cryptocurrency
- Private and Public Keys
- Private Keys
- Public Keys
- Elliptic Curve Cryptography Explained
- Generating a Public Key
- Bitcoin Addresses
- Base58 and Base58Check Encoding
- Key Formats
- Implementing Keys and Addresses in Python
- Advanced Keys and Addresses
- Encrypted Private Keys (BIP-38)
- Pay-to-Script Hash (P2SH) and Multisig Addresses
- Vanity Addresses
- Paper Wallets
- 5. Wallets
- Wallet Technology Overview
- Nondeterministic (Random) Wallets
- Deterministic (Seeded) Wallets
- HD Wallets (BIP-32/BIP-44)
- Seeds and Mnemonic Codes (BIP-39)
- Wallet Best Practices
- Using a Bitcoin Wallet
- Wallet Technology Details
- Mnemonic Code Words (BIP-39)
- Creating an HD Wallet from the Seed
- Using an Extended Public Key on a Web Store
- 6. Transactions
- Introduction
- Transactions in Detail
- Transactions—Behind the Scenes
- Transaction Outputs and Inputs
- Transaction Outputs
- Transaction Inputs
- Transaction Fees
- Adding Fees to Transactions
- Transaction Scripts and Script Language
- Turing Incompleteness
- Stateless Verification
- Script Construction (Lock + Unlock)
- Pay-to-Public-Key-Hash (P2PKH)
- Digital Signatures (ECDSA)
- How Digital Signatures Work
- Verifying the Signature
- Signature Hash Types (SIGHASH)
- ECDSA Math
- The Importance of Randomness in Signatures
- Bitcoin Addresses, Balances, and Other Abstractions
- 7. Advanced Transactions and Scripting
- Introduction
- Multisignature
- Pay-to-Script-Hash (P2SH)
- P2SH Addresses
- Benefits of P2SH
- Redeem Script and Validation
- Data Recording Output (RETURN)
- Timelocks
- Transaction Locktime (nLocktime)
- Check Lock Time Verify (CLTV)
- Relative Timelocks
- Relative Timelocks with nSequence
- Relative Timelocks with CSV
- Median-Time-Past
- Timelock Defense Against Fee Sniping
- Scripts with Flow Control (Conditional Clauses)
- Conditional Clauses with VERIFY Opcodes
- Using Flow Control in Scripts
- Complex Script Example
- 8. The Bitcoin Network
- Peer-to-Peer Network Architecture
- Node Types and Roles
- The Extended Bitcoin Network
- Bitcoin Relay Networks
- Network Discovery
- Full Nodes
- Exchanging “Inventory”
- Simplified Payment Verification (SPV) Nodes
- Bloom Filters
- How Bloom Filters Work
- How SPV Nodes Use Bloom Filters
- SPV Nodes and Privacy
- Encrypted and Authenticated Connections
- Tor Transport
- Peer-to-Peer Authentication and Encryption
- Transaction Pools
- 9. The Blockchain
- Introduction
- Structure of a Block
- Block Header
- Block Identifiers: Block Header Hash and Block Height
- The Genesis Block
- Linking Blocks in the Blockchain
- Merkle Trees
- Merkle Trees and Simplified Payment Verification (SPV)
- Bitcoin’s Test Blockchains
- Testnet—Bitcoin’s Testing Playground
- Segnet—The Segregated Witness Testnet
- Regtest—The Local Blockchain
- Using Test Blockchains for Development
- 10. Mining and Consensus
- Introduction
- Bitcoin Economics and Currency Creation
- Decentralized Consensus
- Independent Verification of Transactions
- Mining Nodes
- Aggregating Transactions into Blocks
- The Coinbase Transaction
- Coinbase Reward and Fees
- Structure of the Coinbase Transaction
- Coinbase Data
- Constructing the Block Header
- Mining the Block
- Proof-of-Work Algorithm
- Target Representation
- Retargeting to Adjust Difficulty
- Successfully Mining the Block
- Validating a New Block
- Assembling and Selecting Chains of Blocks
- Blockchain Forks
- Mining and the Hashing Race
- The Extra Nonce Solution
- Mining Pools
- Consensus Attacks
- Changing the Consensus Rules
- Hard Forks
- Hard Forks: Software, Network, Mining, and Chain
- Diverging Miners and Difficulty
- Contentious Hard Forks
- Soft Forks
- Criticisms of Soft Forks
- Soft Fork Signaling with Block Version
- BIP-34 Signaling and Activation
- BIP-9 Signaling and Activation
- Consensus Software Development
- 11. Bitcoin Security
- Security Principles
- Developing Bitcoin Systems Securely
- The Root of Trust
- User Security Best Practices
- Physical Bitcoin Storage
- Hardware Wallets
- Balancing Risk
- Diversifying Risk
- Multisig and Governance
- Survivability
- Conclusion
- 12. Blockchain Applications
- Introduction
- Building Blocks (Primitives)
- Applications from Building Blocks
- Colored Coins
- Using Colored Coins
- Issuing Colored Coins
- Colored Coins Transactions
- Counterparty
- Payment Channels and State Channels
- State Channels—Basic Concepts and Terminology
- Simple Payment Channel Example
- Making Trustless Channels
- Asymmetric Revocable Commitments
- Hash Time Lock Contracts (HTLC)
- Routed Payment Channels (Lightning Network)
- Basic Lightning Network Example
- Lightning Network Transport and Routing
- Lightning Network Benefits
- Conclusion
- A. The Bitcoin Whitepaper by Satoshi Nakamoto
- Bitcoin - A Peer-to-Peer Electronic Cash System
- Introduction
- Transactions
- Timestamp Server
- Proof-of-Work
- Network
- Incentive
- Reclaiming Disk Space
- Simplified Payment Verification
- Combining and Splitting Value
- Privacy
- Calculations
- Conclusion
- References
- License
- B. Transaction Script Language Operators, Constants, and Symbols
- C. Bitcoin Improvement Proposals
- D. Segregated Witness
- Why Segregated Witness?
- How Segregated Witness Works
- Soft Fork (Backward Compatibility)
- Segregated Witness Output and Transaction Examples
- Upgrading to Segregated Witness
- Segregated Witness’ New Signing Algorithm
- Economic Incentives for Segregated Witness
- E. Bitcore
- Bitcore’s Feature List
- Bitcore Library Examples
- Prerequisities
- Wallet Examples using bitcore-lib
- F. pycoin, ku, and tx
- Key Utility (KU)
- Transaction Utility (TX)
- G. Bitcoin Explorer (bx) Commands
- Examples of bx Command Use
- Index