## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

No credit card required

## Book Description

Dive into Bitcoin technology with this hands-on guide from one of the leading teachers on Bitcoin and Bitcoin programming. Author Jimmy Song shows Python programmers and developers how to program a Bitcoin library from scratch. You’ll learn how to work with the basics, including the math, blocks, network, and transactions behind this popular cryptocurrency and its blockchain payment system.

By the end of the book, you'll understand how this cryptocurrency works under the hood by coding all the components necessary for a Bitcoin library. Learn how to create transactions, get the data you need from peers, and send transactions over the network. Whether you’re exploring Bitcoin applications for your company or considering a new career path, this practical book will get you started.

• Parse, validate, and create bitcoin transactions
• Learn how to use the Bitcoin Script smart contract language
• Work with exercises in each chapter to build a Bitcoin library from scratch
• Understand how to secure a blockchain by verifying proof of work
• Program Bitcoin using Python 3 and libraries including pycoin
• Understand how simplified payment verification and light wallets work
• Work with public-key cryptography and cryptographic primitives

1. Foreword
2. Preface
3. 1. Finite Fields
1. Learning Higher-Level Math
2. Finite Field Definition
3. Defining Finite Sets
4. Modulo Arithmetic
5. Finite Field Addition and Subtraction
6. Finite Field Multiplication and Exponentiation
7. Finite Field Division
8. Redefining Exponentiation
9. Conclusion
4. 2. Elliptic Curves
1. Definition
2. Coding Elliptic Curves in Python
6. Point Addition for When x1≠x2
7. Coding Point Addition for When x1≠x2
8. Point Addition for When P1 = P2
9. Coding Point Addition for When P1 = P2
10. Coding One More Exception
11. Conclusion
5. 3. Elliptic Curve Cryptography
1. Elliptic Curves over Reals
2. Elliptic Curves over Finite Fields
3. Coding Elliptic Curves over Finite Fields
4. Point Addition over Finite Fields
5. Coding Point Addition over Finite Fields
6. Scalar Multiplication for Elliptic Curves
7. Scalar Multiplication Redux
8. Mathematical Groups
9. Coding Scalar Multiplication
10. Defining the Curve for Bitcoin
11. Public Key Cryptography
12. Signing and Verification
13. Conclusion
6. 4. Serialization
1. Uncompressed SEC Format
2. Compressed SEC Format
3. DER Signatures
4. Base58
5. Big- and Little-Endian Redux
6. Conclusion
7. 5. Transactions
1. Transaction Components
2. Version
3. Inputs
4. Outputs
5. Locktime
6. Coding Transactions
7. Transaction Fee
8. Conclusion
8. 6. Script
1. Mechanics of Script
2. How Script Works
3. Example Operations
4. Parsing the Script Fields
5. Combining the Script Fields
6. Standard Scripts
7. p2pk
8. Problems with p2pk
9. Solving the Problems with p2pkh
10. Scripts Can Be Arbitrarily Constructed
11. Conclusion
9. 7. Transaction Creation and Validation
1. Validating Transactions
2. Creating Transactions
3. Creating Your Own Transactions on testnet
4. Conclusion
10. 8. Pay-to-Script Hash
1. Bare Multisig
2. Coding OP_CHECKMULTISIG
3. Problems with Bare Multisig
4. Pay-to-Script-Hash (p2sh)
5. Coding p2sh
6. Conclusion
11. 9. Blocks
1. Coinbase Transactions
3. Proof-of-Work
4. Conclusion
12. 10. Networking
1. Network Messages
3. Network Handshake
4. Connecting to the Network
7. Conclusion
13. 11. Simplified Payment Verification
1. Motivation
2. Merkle Tree
3. Merkle Parent
4. Merkle Parent Level
5. Merkle Root
6. Merkle Root in Blocks
7. Using a Merkle Tree
8. Merkle Block
9. Conclusion
14. 12. Bloom Filters
1. What Is a Bloom Filter?
2. BIP0037 Bloom Filters
4. Getting Merkle Blocks
5. Getting Transactions of Interest
6. Conclusion
15. 13. Segwit
1. Pay-to-Witness-Pubkey-Hash (p2wpkh)
2. p2wpkh Transactions
3. p2sh-p2wpkh
4. Coding p2wpkh and p2sh-p2wpkh
5. Pay-to-Witness-Script-Hash (p2wsh)
6. p2sh-p2wsh
7. Coding p2wsh and p2sh-p2wsh
8. Other Improvements
9. Conclusion
16. 14. Advanced Topics and Next Steps
1. Suggested Topics to Study Next
2. Contributing
3. Suggested Next Projects
4. Conclusion
17. A. Solutions
1. Chapter 1: Finite Fields
2. Chapter 2: Elliptic Curves
3. Chapter 3: Elliptic Curve Cryptography
4. Chapter 4: Serialization
5. Chapter 5: Transactions
6. Chapter 6: Script
7. Chapter 7: Transaction Creation and Validation
8. Chapter 8: Pay to Script Hash
9. Chapter 9: Blocks
10. Chapter 10: Networking
11. Chapter 11: Simplified Payment Verification
12. Chapter 12: Bloom Filters
18. Index