Table of contents : Cover Copyright Table of Contents Preface Writing the Bitcoin Book Intended Audience Why Are There Bugs on the Cover? Conventions Used in This Book Code Examples Using Code Examples Changes Since the Previous Edition Bitcoin Addresses and Transactions in This Book O’Reilly Online Learning How to Contact Us Contacting the Authors Acknowledgments for the First and Second Editions Acknowledgments for the Third Edition Early Release Draft (GitHub Contributions) Chapter 1. Introduction History of Bitcoin Getting Started Choosing a Bitcoin Wallet Quick Start Recovery Codes Bitcoin Addresses Receiving Bitcoin Getting Your First Bitcoin Finding the Current Price of Bitcoin Sending and Receiving Bitcoin Chapter 2. How Bitcoin Works Bitcoin Overview Buying from an Online Store Bitcoin Transactions Transaction Inputs and Outputs Transaction Chains Making Change Coin Selection Common Transaction Forms Constructing a Transaction Getting the Right Inputs Creating the Outputs Adding the Transaction to the Blockchain Bitcoin Mining Spending the Transaction Chapter 3. Bitcoin Core: The Reference Implementation From Bitcoin to Bitcoin Core 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 Configuring the Bitcoin Core Node Bitcoin Core API Getting Information on Bitcoin Core’s Status Exploring and Decoding Transactions Exploring Blocks Using Bitcoin Core’s Programmatic Interface Alternative Clients, Libraries, and Toolkits C/C++ JavaScript Java Python Go Rust Scala C# Chapter 4. Keys and Addresses Public Key Cryptography Private Keys Elliptic Curve Cryptography Explained Public Keys Output and Input Scripts IP Addresses: The Original Address for Bitcoin (P2PK) Legacy Addresses for P2PKH Base58check Encoding Compressed Public Keys Legacy Pay to Script Hash (P2SH) Bech32 Addresses Problems with Bech32 Addresses Bech32m Private Key Formats Compressed Private Keys Advanced Keys and Addresses Vanity Addresses Paper Wallets Chapter 5. Wallet Recovery Independent Key Generation Deterministic Key Generation Public Child Key Derivation Hierarchical Deterministic (HD) Key Generation (BIP32) Seeds and Recovery Codes Backing Up Nonkey Data Backing Up Key Derivation Paths A Wallet Technology Stack in Detail BIP39 Recovery Codes Creating an HD Wallet from the Seed Using an Extended Public Key on a Web Store Chapter 6. Transactions A Serialized Bitcoin Transaction Version Extended Marker and Flag Inputs Length of Transaction Input List Outpoint Input Script Sequence Outputs Outputs Count Amount Output Scripts Witness Structure Circular Dependencies Third-Party Transaction Malleability Second-Party Transaction Malleability Segregated Witness Witness Structure Serialization Lock Time Coinbase Transactions Weight and Vbytes Legacy Serialization Chapter 7. Authorization and Authentication Transaction Scripts and Script Language Turing Incompleteness Stateless Verification Script Construction Pay to Public Key Hash Scripted Multisignatures An Oddity in CHECKMULTISIG Execution Pay to Script Hash P2SH Addresses Benefits of P2SH Redeem Script and Validation Data Recording Output (OP_RETURN) Transaction Lock Time Limitations Check Lock Time Verify (OP_CLTV) Relative Timelocks Relative Timelocks with OP_CSV Scripts with Flow Control (Conditional Clauses) Conditional Clauses with VERIFY Opcodes Using Flow Control in Scripts Complex Script Example Segregated Witness Output and Transaction Examples Upgrading to Segregated Witness Merklized Alternative Script Trees (MAST) Pay to Contract (P2C) Scriptless Multisignatures and Threshold Signatures Taproot Tapscript Chapter 8. Digital Signatures How Digital Signatures Work Creating a Digital Signature Verifying the Signature Signature Hash Types (SIGHASH) Schnorr Signatures Serialization of Schnorr Signatures Schnorr-based Scriptless Multisignatures Schnorr-based Scriptless Threshold Signatures ECDSA Signatures ECDSA Algorithm Serialization of ECDSA Signatures (DER) The Importance of Randomness in Signatures Segregated Witness’s New Signing Algorithm Chapter 9. Transaction Fees Who Pays the Transaction Fee? Fees and Fee Rates Estimating Appropriate Fee Rates Replace By Fee (RBF) Fee Bumping Child Pays for Parent (CPFP) Fee Bumping Package Relay Transaction Pinning CPFP Carve Out and Anchor Outputs Adding Fees to Transactions Timelock Defense Against Fee Sniping Chapter 10. The Bitcoin Network Node Types and Roles The Network Compact Block Relay Private Block Relay Networks Network Discovery Full Nodes Exchanging “Inventory” Lightweight Clients Bloom Filters How Bloom Filters Work How Lightweight Clients Use Bloom Filters Compact Block Filters Golomb-Rice Coded Sets (GCS) What Data to Include in a Block Filter Downloading Block Filters from Multiple Peers Reducing Bandwidth with Lossy Encoding Using Compact Block Filters Lightweight Clients and Privacy Encrypted and Authenticated Connections Mempools and Orphan Pools Chapter 11. The Blockchain 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 Lightweight Clients Bitcoin’s Test Blockchains Testnet: Bitcoin’s Testing Playground Signet: The Proof of Authority Testnet Regtest: The Local Blockchain Using Test Blockchains for Development Chapter 12. Mining and Consensus Bitcoin Economics and Currency Creation Decentralized Consensus Independent Verification of Transactions Mining Nodes 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 Median Time Past (MTP) Successfully Mining the Block Validating a New Block Assembling and Selecting Chains of Blocks Mining and the Hash Lottery The Extra Nonce Solution Mining Pools Hashrate Attacks Changing the Consensus Rules Hard Forks Soft Forks Consensus Software Development Chapter 13. Bitcoin Security Security Principles Developing Bitcoin Systems Securely The Root of Trust User Security Best Practices Physical Bitcoin Storage Hardware Signing Devices Ensuring Your Access Diversifying Risk Multisig and Governance Survivability Chapter 14. Second-Layer Applications Building Blocks (Primitives) Applications from Building Blocks Colored Coins Single-Use Seals Pay to Contract (P2C) Client-Side Validation RGB Taproot Assets 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 Pathfinding Lightning Network Benefits Appendix 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 Appendix B. Errata to the Bitcoin Whitepaper Abstract Transactions Proof of Work Reclaiming Disk Space Simplified Payment Verification Privacy Calculations Appendix C. Bitcoin Improvement Proposals Index About the Authors Colophon