Mastering Bitcoin, 2nd Edition

Book description

Join the technological revolution that’s taking the financial world by storm. Mastering Bitcoin is your guide through the seemingly complex world of bitcoin, providing the knowledge you need to participate in the internet of money. Whether you’re building the next killer app, investing in a startup, or simply curious about the technology, this revised and expanded second edition provides essential detail to get you started.

Bitcoin, the first successful decentralized digital currency, is still in its early stages and yet it’s already spawned a multi-billion-dollar global economy open to anyone with the knowledge and passion to participate. Mastering Bitcoin provides the knowledge. You simply supply the passion.

The second edition includes:

  • A broad introduction of bitcoin and its underlying blockchain—ideal for non-technical users, investors, and business executives
  • An explanation of the technical foundations of bitcoin and cryptographic currencies for developers, engineers, and software and systems architects
  • Details of the bitcoin decentralized network, peer-to-peer architecture, transaction lifecycle, and security principles
  • New developments such as Segregated Witness, Payment Channels, and Lightning Network
  • A deep dive into blockchain applications, including how to combine the building blocks offered by this platform into higher-level applications
  • User stories, analogies, examples, and code snippets illustrating key technical concepts

Publisher resources

View/Submit Errata

Table of contents

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

Product information

  • Title: Mastering Bitcoin, 2nd Edition
  • Author(s): Andreas M. Antonopoulos
  • Release date: June 2017
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781491954386