BitCoin and Cryptocurrencies NO.STARCH.PRESS.BITCOIN.FOR.THE.BEFUDDLED.2015.RETAIL.EBOOK kE

Bitcoin for the Befuddled
arski
ilmer

Conrad Barski and Chris Wilmer
Safety Area: All Text, Logos & Barcode should remain inside the Pink Dotted Lines
Bleed Area: All Backgrounds should extend to, but not past, the Blue Dotted Lines

BITCOIN FOR THE BEFUDDLED

BITCOIN
FOR THE
BEFUDDLED

by Co n r a d Bar s k i a nd C hr i s W i lm er

San Francisco

BITCOIN FOR THE BEFUDDLED. Copyright © 2015 by Conrad Barski and Chris Wilmer.
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, or by any information storage or retrieval

system, without the prior written permission of the copyright owner and the publisher.
Printed on demand in USA.
ISBN-10: 1-59327-573-0
ISBN-13: 978-1-59327-573-0
Publisher: William Pollock
Production Editor: Serena Yang
Cover Illustration: Conrad Barski
Interior Design: Octopod Studios
Developmental Editor: Tyler Ortman
Technical Reviewer: Patrick Fuller
Copyeditor: Anne Marie Walker
Compositor: Alison Law
Proofreader: Paula L. Fleming
Indexer: Nancy Guenther
For information on distribution, translations, or bulk sales, please contact No Starch Press, Inc. directly:
No Starch Press, Inc.
245 8th Street, San Francisco, CA 94103
phone: 415.863.9900; info@nostarch.com
www.nostarch.com
Library of Congress Control Number: 2014951031

No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other
product and company names mentioned herein may be the trademarks of their respective owners. Rather
than use a trademark symbol with every occurrence of a trademarked name, we are using the names only
in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The information in this book is distributed on an “As Is” basis, without warranty. While every precaution
has been taken in the preparation of this work, neither the authors nor No Starch Press, Inc. shall have any
liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or
indirectly by the information contained in it.
Nothing in this book is intended to offer legal or financial advice, and neither the authors nor the publisher
are engaged in the business of rendering such advice. If you’re looking for legal or financial advice, please
run to the nearest qualified professional and don’t ask us. Neither the authors nor the publisher will be
liable for any loss or risk that you incur by using the information contained in this book.

About the Authors
Conrad Barski has an M.D. from the University of Miami and nearly
20 years of programming experience. Barski is a cartoonist, programmer,
and the author of Land of Lisp (No Starch Press). He’s been using Bitcoin
since 2011.
Chris Wilmer holds a Ph.D. in chemical engineering from Northwestern

University and is a professor at the University of Pittsburgh. Wilmer’s first
purchase with Bitcoin was a bag of honey caramels from a farm in Utah.
They were delicious.

BRIEF CONTENTS

Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Chapter 1: What Is Bitcoin? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Chapter 2: Bitcoin Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Chapter 3: Storing Your Bitcoins Safely, Securely, and Conveniently . . . . . . . . . . . . . . . . . 31
Chapter 4: Buying Bitcoins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Chapter 5: Lost at Sea: A Cryptographic Adventure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Chapter 6: Why Bitcoin Is a Big Deal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Chapter 7: The Cryptography Behind Bitcoin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Chapter 8: Bitcoin Mining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Chapter 8.5: The Strange World of Altcoins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Chapter 9: Understanding the Different Types of Bitcoin Wallets . . . . . . . . . . . . . . . . . . . 185
Chapter 10: Bitcoin 2030. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Appendix A: Hello Money! A Simple JavaScript Program . . . . . . . . . . . . . . . . . . . . . . . . 213
Appendix B: Bitcoin Programming with BitcoinJ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241

CONTE NT S IN DE TA IL

PREFACE

xv

Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi

1
WHAT IS BITCOIN?
Why Bitcoin Now?. . . . . . . . . . . . . . . .
The Benefits of Using Bitcoin . . . . . . . . .
The Complexity and Confusion of Bitcoin
What’s in This Book? . . . . . . . . . . . . . .

1
.
.

.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.

.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.

.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.

.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.

.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.

.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.

.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

2
BITCOIN BASICS

2
3
4
5

7

How Bitcoin Works in Simple Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Bitcoin Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The Bitcoin Address . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The Private Key . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The Bitcoin Wallet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating Your First Bitcoin Wallet with Electrum . . . . . . . . . . . .
Acquiring Bitcoins in Your Wallet . . . . . . . . . . . . . . . . . . . . . .
Spending Bitcoins with Your Wallet. . . . . . . . . . . . . . . . . . . . .
Bitcoin Addresses Generated by Your Bitcoin Wallet Program . .
The Blockchain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The Blockchain Lottery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Blockchain Forking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Transaction Confirmations, Double Spending , and Irreversibility .
Mining Bitcoins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The Complexity of the Bitcoin System . . . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

3
STORING YOUR BITCOINS SAFELY, SECURELY,
AND CONVENIENTLY
Storing Your Private Key(s) . . . . . . . . . . . .
Hot Storage vs. Cold Storage . . . . . . . . . .
Personal vs. Hosted Wallets . . . . . . . . . . .
Safety, Security, and Convenience . . . . . . .
Storing Small Amounts of Bitcoins . . . . . . .
Online Hosted Wallet Services . .
Online Personal Wallet Services .
Personal Hot Wallet . . . . . . . . .

.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

. 8
. 9
10
11
12
14
16
17
19
19
21
23
25
26
27

31
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

33
33
34
35
35
36
37
37

Storing Large Amounts of Bitcoins . . . . . . . . . . . . . . . . . . . . . . .
Paper Wallets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Encrypted Paper Wallets . . . . . . . . . . . . . . . . . . . . . .
Offline Transaction Signing . . . . . . . . . . . . . . . . . . . .
Fragmented Private Keys and Multi-Signature Addresses
Special Mention: The Bitcoin Hardware Wallet . . . . . . . . . . . . . .
Special Mention: The Bitcoin Brain Wallet. . . . . . . . . . . . . . . . . .
Choosing the Storage Method That’s Right for You . . . . . . . . . . . .

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

4
BUYING BITCOINS

49

Why Not Just Mine Bitcoins? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Ways to Buy Bitcoins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Buying Bitcoins the Easy Way . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Authentication Factors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The Hassle of Converting Dollars (or Other Currencies) into Bitcoins
Buying Bitcoins with Coinbase . . . . . . . . . . . . . . . . . . . . . . . . . .
Buying Bitcoins the Efficient Way . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Buying Bitcoins from a Currency Exchange . . . . . . . . . . . . . . . . .
Buying Bitcoins the Fun and Futuristic Way . . . . . . . . . . . . . . . . . . . . . . . . .
Step 1: Finding Someone to Buy From . . . . . . . . . . . . . . . . . . . . .
Step 2: Deciding on a Meeting Place . . . . . . . . . . . . . . . . . . . . .
Step 3: Handing Over the Money and Getting Your Bitcoins . . . . .
Satoshi Square . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Still Don’t See a Buying Option That Works for You? . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

5
LOST AT SEA: A CRYPTOGRAPHIC ADVENTURE

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

A Brief Cryptography Overview. . . . . . . . . . . . . . . . . . . .
One-Way Functions. . . . . . . . . . . . . . . . . . . . .
Cryptographic Hash Functions Verify Information
Public Key Cryptography . . . . . . . . . . . . . . . . .

Contents in Detail

50
51
52
54
55
58
62
65
67
67
68
68
70
71

109
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

7
THE CRYPTOGRAPHY BEHIND BITCOIN

x

.
.
.
.
.
.
.
.
.
.
.
.
.
.

73

6
WHY BITCOIN IS A BIG DEAL
A Brief History of Digital Currencies . . . . . . . . . . . . . .
The Dawn of Bitcoin . . . . . . . . . . . . . . . . . . . . . . . . .
Bitcoin’s First Four Years . . . . . . . . . . . . . .
Bitcoin’s Early Impact . . . . . . . . . . . . . . . .
The Future Potential of Bitcoin . . . . . . . . . . . . . . . . . .
What Are the Existential Risks to Bitcoin? . . .
What Role Might Bitcoin Play in the Future? .
The Dangers of Decentralized Digital Money

38
39
39
40
41
42
45
46

110
112
113
115
116
117
121
123

129
.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

130
131
132
133

Digital Signatures . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using Digital Signatures. . . . . . . . . . . . . . . . . . . . . . . . .
Why Bitcoin Needs Cryptography . . . . . . . . . . . . . . . . . . . . . . . . .
Authorizing Transactions with Digital Signatures . . . . . . . .
Verifying the Validity of the Transaction History . . . . . . . .
Proof-of-Work in Bitcoin Mining . . . . . . . . . . . . . . . . . . .
Extra Protection for Bitcoin Private Keys . . . . . . . . . . . . .
Cryptographic Methods Used in Bitcoin . . . . . . . . . . . . . . . . . . . . .
Cryptographic Hash Functions: SHA256 and RIPEMD160
Crowley and the Unfortunate Jelly-Filled Donut Incident . . . . . . . . . . .
Moving Around on a Line . . . . . . . . . . . . . . . . . . . . . . .
Elliptic Curve Digital Signature Algorithm (ECDSA) . . . . . .
Signing a Bitcoin Transaction Using ECDSA . . . . . . . . . . .
The Security of Bitcoin’s Cryptography . . . . . . . . . . . . . . . . . . . . . .
Pseudocode for Elliptic Point Summation and Point Multiplication . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

8
BITCOIN MINING
Why Is Bitcoin Mining Needed? . . . . . . . . . . . . .
A Parable of Two Generals . . . . . . . . .
Applying the Parable to Bitcoin. . . . . . .
Preventing Attacks with Mining . . . . . . .
Distributing New Currency with Mining .
How Does Bitcoin Mining Work? . . . . . . . . . . . . .
How Miners Solve a Block . . . . . . . . . .
Anatomy of a Block. . . . . . . . . . . . . . .
Pooled Mining . . . . . . . . . . . . . . . . . .
Bitcoin Mining for Profit . . . . . . . . . . . . . . . . . . .
Theoretical Hash Rate Limits . . . . . . . . . . . . . . . .
Decentralization in Bitcoin Mining . . . . . . . . . . . .

135
136
137
137
138
138
139
139
140
141
145
146
154
158
159

161
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

162
162
164
166
167
168
171
171
175
176
178
179

8.5
THE STRANGE WORLD OF ALTCOINS

181

9
UNDERSTANDING THE DIFFERENT TYPES
OF BITCOIN WALLETS

185

Wallet Software Design Fundamentals . . . . . . . . . . . . . . . . . . . . . .
Offline vs. Online Transaction Signing. . . . . . . . . . . . . . .
Random Key Generation vs. Deterministic Key Generation
(vs. Single Key Generation) . . . . . . . . . . . . . . . . . . . .
Full vs. Simplified Payment Verification . . . . . . . . . . . . . .
Other Common (and Not So Common) Bitcoin Wallet Features . . . . .
Future Wallets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Which Wallet Is Right for You? . . . . . . . . . . . . . . . . . . . . . . . . . . .
Additional Wallet Considerations. . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . 186
. . . . . . . . . . . . 186
.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

187
191
195
197
197
197

Contents in Detail

xi

10
BITCOIN 2030
What Will a Bitcoin Be Worth in 2030?.
Bitcoin Mining in 2030. . . . . . . . . . . . .
A Day in the Life of a Bitcoiner in 2030 .
The Bitcoin End Game . . . . . . . . . . . . .

199
.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

A
HELLO MONEY! A SIMPLE JAVASCRIPT PROGRAM
The Meaning of “Easy”. . . . . . . . . . . . . . . . . . . . . . . . . . . .
Three Ways to Write Bitcoin Software . . . . . . . . . . . . . . . . .
General Security Notes on Bitcoin Programming . . . . . . . . . .
Some Upbeat Notes on Bitcoin Security . . . . . . . . . . . . . . . .
Writing Your First Bitcoin Program in JavaScript. . . . . . . . . . .
Why Use JavaScript?. . . . . . . . . . . . . . . . . . . . . .
Bitcoin Core vs. Bitcoind . . . . . . . . . . . . . . . . . . .
Preparing Your Machine for JavaScript Bitcoin Programming. .
Installing Node.js . . . . . . . . . . . . . . . . . . . . . . . .
Installing node-bitcoin . . . . . . . . . . . . . . . . . . . . .
Starting Bitcoin Core . . . . . . . . . . . . . . . . . . . . . .
For Mac Hackers . . . . . . . . . . . . . . . . . . . . . . . .
For Linux Folks . . . . . . . . . . . . . . . . . . . . . . . . . .
Hello Money! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Part 1: Initializing the Connection with Bitcoin Core
Part 2: The Main Loop . . . . . . . . . . . . . . . . . . . . .
The Bitcoin Core JSON-RPC API . . . . . . . . . . . . . .
Running the Hello Money! App . . . . . . . . . . . . . . . . . . . . . .
Limitations of Writing Bitcoin Programs That Use JSON-RPC . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

213
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

B
BITCOIN PROGRAMMING WITH BITCOINJ
The Best Programming Language for Connecting to the Bitcoin Network .
Installing Java, Maven, and the BitcoinJ Library . . . . . . . . . . . . . . . . . .
Step 1: Installing Java . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Step 2: Installing Maven . . . . . . . . . . . . . . . . . . . . . . . . . .
Step 3: Installing Git . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Step 4: Installing BitcoinJ . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating a Starter Project for hello-money . . . . . . . . . . . . . . . . . . . . . .
Writing the Code for hello-money . . . . . . . . . . . . . . . . . . . . . . . . . . .
Declarations at the Top of the Program . . . . . . . . . . . . . . . .
Initializing Our Java Objects . . . . . . . . . . . . . . . . . . . . . . .
Connecting to the Bitcoin Network . . . . . . . . . . . . . . . . . . .
Listening for New Money . . . . . . . . . . . . . . . . . . . . . . . . . .

xii

Contents in Detail

200
201
202
210

213
214
215
216
217
217
217
218
218
218
218
219
219
220
220
221
222
222
223

225
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.

225
226
226
227
227
227
228
230
231
231
233
234

Running and Testing the hello-money Java Program
Bye-Bye Money . . . . . . . . . . . . . . . . . . . . . . . . .
Importing a Private Key . . . . . . . . . . . .
Sending the Money . . . . . . . . . . . . . . .
Ensuring the Money Transmission . . . . .
Running bye-bye-money . . . . . . . . . . . .
Gotchas When Using Wallets in BitcoinJ. . . . . . . .
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . .

INDEX

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

235
236
237
238
238
238
239
240

241

Contents in Detail

xiii

PREFACE

In writing this book, we wanted to explain the concept and potential of Bitcoin in a more-or-less timeless manner. Boy, was that hard. It would have been
much easier to write a book called The State of Bitcoin
Right Now: Please Disregard Everything in This Book One
Year After Its Publication. The core technology behind
Bitcoin, as well as the larger technological infrastructure around it, is rapidly evolving as this book goes to press. The debates about the legality, price
volatility, and merchant adoption of Bitcoin may already be out of date by
2015, and who knows how they will sound in 2025.
To keep this book relevant for the future, we did our best to focus on
those aspects of Bitcoin that will remain important forever, and we tried to
cover them in a way that is fun. We hope you will enjoy our approach to this
fascinating subject.

Acknowledgments
Chris Wilmer would like to thank his wife Emily Winerock and his family
for their patience and early feedback. Conrad Barski would like to thank
his wife Lauren Barski and daughter Ava Barski for their support as he was
working on this book and for their patience during all the weekends and
evenings he spent to get it done.
Special thanks go to Richard Ford Burley, for substantial editorial help
in the early drafts of this book, and to Patrick Fuller, for reviewing the programming sections. Many of the great people at No Starch Press helped
us to get this book into shape, including Serena Yang, Tyler Ortman, Bill
Pollock, and others.

xvi

Preface

1
W H AT IS BI TCOIN?

In the simplest terms, Bitcoin is just another currency.
The term Bitcoin refers to the entire currency system,
1
whereas bitcoins are the basic units of the currency.
As with dollars, euros, yen, and gold coins, you can
save bitcoins, spend them on goods and services, and exchange them for
other currencies. However, Bitcoin is the world’s first currency that is both
digital and decentralized.
A digital currency is one that can be easily stored and used on a computer. By this definition, even dollars can be considered a digital currency,
since they can be easily sent to others or used to shop online, but their supply is controlled by a centralized bank organization. In contrast, gold coins
are decentralized, meaning that no central authority controls the supply of
gold in the world. In fact, anyone can dig for gold, create new coins, and
distribute them. However, unlike digital currencies, it’s not easy to use gold
coins to pay for goods (at least not with exact change!), and it’s impossible
to transfer gold coins over the Internet. Because Bitcoin combines these two

1. Similar to how renminbi is name of the Chinese currency, but the yuan is the basic unit.

properties, it is somewhat like digital gold.
Never before has there been a currency
with both these two properties, and its
impact on our increasingly digital, globalized world may turn out to be significant.
Sometimes called a stateless currency,
Bitcoin is not associated with any nation.
However, you should not consider Bitcoin
to be in the same category as private currencies, hundreds of which have existed in various forms in the past.2 Private currencies,
whether issued by a person, a company,
or a nonstate organization, are centrally
controlled and run the risk of collapse due
to bankruptcy or other economic failure.
Bitcoin is not a company, nor does a single
person or organization issue or control bitcoins; therefore, it has no central point of failure. For this reason, nobody
can inflate the currency supply and create hyperinflation crises, such as
those that occurred in post–World War I Germany and more recently in
Zimbabwe.3
Many people are asking about the motive behind the creation of
Bitcoin, so let’s explore the currency’s purpose.

Why Bitcoin Now?
Until recently, people could not send digital cash back and forth to each
other in a reliable way without a central mediator. A trusted central mediator such as PayPal can track payments and money transfers in a privately
held account ledger, but it wasn’t clear how a group of strangers who do
not trust each other could accomplish the same transactions dependably.4
Sometimes referred to as the Byzantine Generals’ Problem, this fundamental conundrum also emerges in computer science, specifically in how to
achieve consensus on a distributed network.

2. For example, in the mid-1800s, banks, companies, churches, and individuals issued hundreds of private currencies in the United States. Eventually, most of these private currencies
lost all their value.
3. Between 1921 and 1924, the value of the German mark fell by a factor of more than 10 trillion due to overprinting by the government. In 2008, the government of Zimbabwe printed
so much of its currency that in a single year, a loaf of bread increased from $1 to $100 billion.
In both cases, any savings that people had in the form of national currency were completely
destroyed.
4. To say that something is decentralized is more or less equivalent to saying that it is run by a
group of strangers who don’t necessarily trust each other.

2

Chapter 1

In 2008, the problem was elegantly solved by Bitcoin’s inventor, known
pseudonymously as Satoshi Nakamoto. Satoshi’s significant breakthrough
made it possible for a digital currency to exist without relying on a central authority. Satoshi described the solution to the Byzantine Generals’
Problem and the invention of Bitcoin in a white paper titled “Bitcoin: A
Peer-to-Peer Electronic Cash System.” But the creation of the software that
demonstrated the concept in practice was released a year later.
Although the first version of the software was written by Satoshi, it
quickly became a community project as the software was improved and
maintained by hundreds of volunteers. Currently, the software is open
source, and anyone can read and contribute to it. In January of 2009,
the first bitcoins were distributed using the early Bitcoin software, and
since then transactions have been running smoothly. Slowly but surely, an
increasing number of people have started using Bitcoin, and what began
as an experiment is now a multibillion dollar economy that processes hundreds of thousands of transactions per day (and is growing quickly).

The Benefits of Using Bitcoin
Bitcoin is an inherently international currency; anyone can send bitcoins
to anyone else in the world, in any amount, almost instantly. In addition,
it is becoming increasingly possible to travel the world and spend bitcoins
without having to change them into the local currency. Because no middleman is involved, transaction fees are negligible. Unlike with credit cards,
which require giving online merchants your personal information, you can
use bitcoins to shop online while maintaining your privacy. There is no
risk of losing your savings due to runaway inflation because bitcoins were
designed to have a fixed supply. Bitcoins are also fundamentally impossible
to counterfeit.
As a merchant, you can start accepting bitcoins as payment immediately
without filling out tedious paperwork (compared to setting up the credit
card transaction process). You can also own bitcoins without anyone else
knowing, and no third party or government can seize your money. (The
privacy this feature entails may protect the security and freedom of political
dissidents living under repressive regimes, for example.)
Thanks to all of its benefits, Bitcoin continues to increase in popularity;
however, anyone familiar with Bitcoin will agree the technology behind it is
difficult to explain and understand. At first blush, it’s hard to grasp how
bitcoins are stored, how they are used, or even where they come from.

What Is Bitcoin?

3

The Complexity and Confusion of Bitcoin
Rarely do we get to see the creation of a new currency, let alone one that is
so different from previous currencies. This creates major challenges in comprehension and comfort for most people.
Bitcoin can be compared to the advent of paper currency years ago
when everyone was using gold and silver coins. Then, it must have seemed
strange and confusing to attribute value to little pieces of paper instead of
precious metals. Today, paper currency feels fairly safe, and trading paper
for a purely digital asset like bitcoins seems odd. Furthermore, the economic
and social consequences of switching to a decentralized digital currency are
still unclear. Even Satoshi and the early volunteers who helped develop the
concept could not have imagined precisely how Bitcoin would be used and
valued by society, much as the creators of the Internet in the 1980s could not
have predicted how transformative it would become.
Confusion also stems from the fact that Bitcoin is a truly complex technology. It relies not only on Satoshi’s breakthrough to achieving consensus
on a distributed network but also on modern cryptographic techniques,
such as digital signatures, public/private key pairs, and secure hashing.
(These cryptographic concepts are covered in detail in Chapter 7.) The
4

Chapter 1

issuing of new currency occurs through a cryptographic lottery called
mining that anyone can participate in. Mining simultaneously processes
transactions made by Bitcoin users. To resist abuse from those who might
want to destroy the network, Bitcoin’s design uses game theory to align the
incentives of those who maintain the network and those who want to act in
their own selfish interest. (Bitcoin mining and game theory is explained in
detail in Chapter 8.)
Put simply, you cannot learn and completely understand Bitcoin in a
single afternoon. However, we hope this book will help you understand the
basics of Bitcoin as quickly as possible.

What’s in This Book?
To make sense of the Bitcoin technology and phenomenon, you must
view it from multiple perspectives. This book is organized around those
perspectives.









First, we’ll look at Bitcoin from the perspective of a basic user. In
Chapters 2–4 we describe how Bitcoin works and how you can acquire,
spend, and safely store bitcoins—so you can actually start using Bitcoin.
Next, in Chapters 5 and 6, we take a philosophical perspective on
Bitcoin. Chapter 5 is an adventure story told from the perspective of
Crowley the cryptographer. Crowley gets stranded on an island and
needs to figure out how to efficiently exchange goods with inhabitants
of other distant islands. Crowley knows about Bitcoin from a chance
encounter with Satoshi but has significant doubts about the currency.
In the story, he works through his doubts (which may be similar to
yours) by giving Bitcoin a chance.
Chapter 6 continues in this philosophical vein by looking at the
potentially broader impact of Bitcoin and the potentially uneasy relationship of Bitcoin and its users with nation states whose currencies
compete with Bitcoin.
Then, we’ll look at Bitcoin from the perspective of an advanced user.
Chapters 7–9 describe the cryptographic methods behind Bitcoin, the
details of bitcoin mining, and the nuances of various third-party wallet
software solutions.
Finally, in Chapter 10, we’ll look at what the distant future might look
like in a world where Bitcoin has gone mainstream.
For programmers and developers who are new to Bitcoin, the appendices show you how to write your own programs to send and receive
bitcoins.

As you read this book, keep in mind just how new Bitcoin is as a technology. For fields like particle physics, Egyptian history, or constitutional
law, we can turn to authority figures that have devoted the better part of
their lives to studying those subjects; by comparison nobody is really an

What Is Bitcoin?

5

expert on Bitcoin. Just as there were no electricians before the discovery of
electricity or programming gurus before computers were invented, arguably no Bitcoin experts exist today. We are all Bitcoin beginners, and no
one can predict with any clarity how Bitcoin will evolve, even a year or two
into the future.
On the upside, this means that if Bitcoin becomes widely used in the
future, the potential exists for you to become one of the early experts in
Bitcoin, since you are studying this technology at such an early stage. We
hope you will be inspired by the ideas behind Bitcoin and will make your
own contributions to this wonderful technology in years to come.
Now, let’s learn some Bitcoin basics.

6

Chapter 1

2
BITCOIN BA SICS

In our experience, the simplest way to get a person
excited about Bitcoin is to have him purchase something with it. That’s how we got hooked ourselves. In
this chapter, we’ll help you perform your first Bitcoin
transaction, without worrying about too much technical stuff. Along the way, though, we’ll discuss how
Bitcoin works. After reading this chapter, you’ll understand the basics of Bitcoin—enough to chat about it at
any cocktail party.

How Bitcoin Works in Simple Terms
In the Bitcoin system, everyone cooperates to keep track of everyone else’s
money, and as mentioned in Chapter 1, no central authority (e.g., bank or
government) is involved. To best understand how the system works, let’s
walk through an example using dollars first.
Imagine only $21 million exists in the world, and there also exists a
detailed list of all the people who possess that money. Everyone, including
you (even though you have only $5), has a copy of this list. When you give
$2 to your friend, you must subtract $2 from your entry on the list and add $2
to her entry. After informing her of the transaction, she updates her list as
well. In fact, everyone in the world needs to update the list; otherwise, the list
would be inaccurate. Therefore, not only do you need to notify your friend,
but you also need to publicly announce that you are updating the list. If you
tried to cheat the system and send your friend $1000, your cheating attempt
would be easy to catch because everyone knows you have only $5 to give.
Now, imagine that all transactions are carried out on computers that
communicate via the Internet, and replace dollars with bitcoins. This is how
Bitcoin works. Pretty simple actually. So why does Bitcoin seem so complex?
8

Chapter 2

The answer is threefold: First is the tricky question of how the units of
any new currency system (whether bitcoins or seashells) should be valued.
Should a haircut be worth 5000 bitcoins or 0.005 bitcoins? Second, many
small details are involved in implementing and using Bitcoin, even though
the overall concept is fairly straightforward. For example, how do you obtain a
copy of the list, and how are bitcoins initially distributed? Third, an entire lexicon of new and unfamiliar words (e.g., mining) is used in the Bitcoin world.
We’ll leave the first point about the value of bitcoins for a later chapter.
In this chapter, we’ll address the last two points by explaining the major
concepts used in Bitcoin, namely the Bitcoin address, the private key, the
Bitcoin wallet, and the blockchain. We’ll also briefly discuss Bitcoin mining and walk you through the process of receiving and sending your first
bitcoins so you can see how the system works. But first, you need to understand the Bitcoin units in more detail.

Bitcoin Units
As explained in Chapter 1, Bitcoin refers collectively to the entire currency
system, whereas bitcoins are the units of the currency. Although the total
currency supply is capped at 21 million bitcoins, each one can be subdivided
into smaller denominations; for example, 0.1 bitcoins and 0.001 bitcoins.
The smallest unit, a hundred millionth of a bitcoin (0.00000001 bitcoins),
is called a satoshi in honor of Satoshi Nakamoto. As a result, goods can be
priced in Bitcoin very precisely, and people can easily pay for those goods in
exact change (e.g., a merchant can price a gallon of milk at 0.00152374 bitcoins, or 152,374 satoshis).
Rather than writing the term bitcoins on price tags, merchants commonly use the abbreviated currency code BTC or XBT; 5 bitcoins would
be written as 5 BTC. Despite the fact that the BTC abbreviation has been
widely used since the beginning of Bitcoin’s development, more recently
some merchants and websites have started using XBT because it conforms
better to certain international naming standards.1 As bitcoins have appreciated in value, it has become increasingly common to work with thousandths
or even millionths of bitcoins, which are called millibitcoins (mBTC) and microbitcoins (µBTC), respectively. Many people have suggested simpler names for
Bitcoin’s smaller denominations, and one that has gained traction is referring
to microbitcoins (quite a mouthful) as simply as bits.
1 bitcoin = 1 BTC or 1 XBT
1 BTC = 1,000 mBTC
1 mBTC = 1,000 µBTC
1 µBTC = 100 satoshis = 1 bit

1. The standard for currency codes (ISO 4217) uses the first character in the code to refer to
the country issuing the currency. However, since Bitcoin is a nongovernmental currency, the
standard suggests that its name should start with X, as is the case with gold or silver, whose
codes are XAU and XAG, respectively.
Bitcoin Basics

9

Now that you know the terms for various Bitcoin units, you need to
increase your Bitcoin vocabulary, so let’s talk about what is meant by a
Bitcoin address.

The Bitcoin Address
Bitcoin uses a public ledger that indicates the number of bitcoins and their
owners at any given time. But instead of associating names of people with
accounts, the ledger only lists Bitcoin addresses. Each address can be thought
of as a pseudonym for a person (or group of people, business, etc.), and the
use of pseudonyms is why people can use bitcoins without revealing personal information. The following is an example of a Bitcoin address:
13tQ1fbTMB6GxUJfMqCSDgivc8fvkHEh3J

Like a bank account number, a Bitcoin address consists of a string of letters and numbers (usually beginning with the number 1). To send bitcoins
to others (e.g., an online merchant, a friend, or a family member), you only
need to know their Bitcoin address. In turn, when you share your address
with others, they can send you bitcoins. Because Bitcoin addresses are cumbersome to type, many people use quick response (QR) codes to represent their
address (see Figure 2-1).2 For convenience, you can put your Bitcoin address,
either typed or as a QR code (or both), on your business card, personal website, or storefront (if you’re a merchant). Although you need an Internet
connection to send bitcoins, you don’t need to be connected to receive them.
For example, if you work for a charity and pass out thousands of business
cards containing your Bitcoin address and a statement like “Please consider
donating in bitcoins,” your organization can collect bitcoins while you sleep.

= "hello world"

"16r61N8tBo3FTQGwZ
CRXLLygNqVL8NEsrR" =

Figure 2-1: QR codes can be used to represent arbitrary data. They are easy to scan with smartphones
and so are convenient for sharing the long strings of
characters used for Bitcoin addresses.

2. The QR code is just one of many ways to easily share a Bitcoin address. Another method
is to use a first bits scheme in which you share only the first few characters of your Bitcoin
address, which has been abbreviated by a Bitcoin address–shortening services (similar to a
URL-shortening service). Starting with version 0.9 and later, Bitcoin also supports humanreadable Bitcoin addresses that replace the traditional ones—much as a website address such
as toys.com replaces the less user-friendly IP address of 123.100.101.111.

10

Chapter 2

As you know, in traditional banking, moving money from one account
to another means that the bank would update its privately held ledger that
listed every account at that bank. If a fire or other disaster destroyed that
ledger, information about who owned the assets at the bank might be lost
forever. Although Bitcoin also uses a ledger, identical copies of it are distributed across millions of computers around the world. Consequently, no central point of failure exists, and transactions recorded on the Bitcoin ledger
are permanent and impossible to erase. Moving bitcoins from one address
to another is equivalent to sending an instruction to all of the computers on
the Bitcoin network to update each ledger in the same way.
Because all transactions on the Bitcoin ledger are public information,
maintaining privacy (if that is desired) can be a challenge. Although no personal information is on the ledger, if you share your Bitcoin address with your
friends or post it in a public place that others can associate with your identity,
your Bitcoin balance at that address will be known to everyone (including all
incoming and outgoing transactions). To enhance your privacy, you can use
many Bitcoin addresses but publicly share only some of them.3
So how do you move bitcoins from one address to another (i.e., spend
them)? Well, this action requires a private key.

The Private Key
A private key, like a Bitcoin address, is a long string of numbers and letters
(usually beginning with the number 5). As with Bitcoin addresses, QR
codes are often used to represent private keys because of their length. Each
private key is paired with a single Bitcoin address and is able to unlock the
bitcoins at that address (i.e., move them elsewhere).4 The following is an
example of a private key:
5J2ae37Jwqzt7kSp9rE17Mi2LbkHXx4tzNSzbq7xDp2cQJCzhYo

Whereas a Bitcoin address is similar to a bank account number, a
private key is more like a PIN: You need it to authorize a withdrawal or
an expenditure. When a transaction is broadcast to the Bitcoin network,
instructing bitcoins to be moved from one address to another, computers
on the network check whether the transaction is authorized before making any updates to the public ledger. Specifically, they check whether the
transaction has been digitally signed using a private key. A digital signature is extra data appended to a transaction that can only be created by

3. In general, maintaining complete privacy while doing online transactions is very difficult,
with or without Bitcoin. Although the use of Bitcoin helps protect privacy when compared to
using a credit card, it is not a complete solution. Other tools and precautions might need to
be used as well (for example, using the online privacy-protecting TOR browser).
4. Although every private key is associated with a single Bitcoin address, the reverse is not
always true. A Bitcoin address can require multiple private keys to unlock the bitcoins at that
address (in this case, the Bitcoin address will begin with the number 3 instead of the usual 1).
However, this advanced feature isn’t used for most common transactions.
Bitcoin Basics

11

someone possessing the corresponding private key. Similar to a PIN, a private key should be kept secret. If someone obtains your private key, he will
be able to spend your bitcoins.
Note that although a private key can be used to produce a digital signature, a digital signature cannot be used to obtain a private key. Digital
signatures also cannot be reused to make new transactions; therefore, broadcasting a signed transaction to the Bitcoin network is not a risk. This action is
fundamentally different from making an online payment with a credit card.
When you use a credit card, you provide your credit card number to someone
to authorize a transaction. That number can then be reused (maliciously) to
authorize more transactions that you never intended.
Unlike a PIN, which both you and the bank know, only you know the
private key. The risk you take in this circumstance is if you lose the private
key to an address in which you’ve stored bitcoins, those bitcoins will remain
locked in that address forever. Clearly, it is extremely important not to lose
your private key! Fortunately, you can easily make digital backups of your
private keys or write them on a piece of paper and keep them in a safe
place. Losing your Bitcoin address is not a problem, however, as it can be
recovered from the corresponding private key (Bitcoin wallet programs,
described later in this chapter, can do this for you automatically).
Although it’s possible to use Bitcoin with only a single address and
private key, in practice most people use many addresses, each with its
own private key, and store them in a digital wallet.

The Bitcoin Wallet
A Bitcoin wallet is a collection of addresses and private keys owned by one person. Having multiple Bitcoin addresses can help you organize your money.
You may want separate addresses for paying rent, for shopping online, and
for saving bitcoins to pay for a house in the future. So a person could have
two bitcoins in his wallet that are distributed among many different Bitcoin
addresses (see Figure 2-2).
Using multiple addresses, in the form of a wallet, also helps you maintain privacy. This is because the public ledger maintained by Bitcoin, which
anyone can look at, has no way of knowing that any two addresses are in
the same wallet and are owned by the same person (as long as that person
hasn’t done anything to show that the two addresses are linked, such as
making a single purchase using bitcoins from both accounts).
To manage several addresses and private keys, people use Bitcoin wallet programs.5 Whereas a Bitcoin wallet is an abstract concept, referring to a
group of Bitcoin addresses, a wallet program is a concrete tool that helps
users with common Bitcoin tasks, such as creating new Bitcoin addresses,
sending bitcoins to others, backing up private keys, and many others. But
be aware that the terminology surrounding Bitcoin wallets is not always

5. Also called Bitcoin wallet clients.

12

Chapter 2

used consistently. Often, Bitcoin wallet programs are called Bitcoin wallets
for short, confusing these two distinct concepts. When you save a Bitcoin
wallet (perhaps to make a backup copy), you create a wallet file, which contains information for multiple Bitcoin addresses. Later, you can load your
wallet files into a Bitcoin wallet program.

Bitcoin Wallet Program
Create wallet

Load wallet

My Personal Bitcoin Wallet

Total balance: 347,500 bits (.3475 BTC)

Bitcoin address #1
Private key #1

College savings fund
(300,000 bits)

Generate new address

Bitcoin address #2
Private key #2

Money from Dave
(12,500 bits)

Send bitcoins

Bitcoin address #3
Private key #3

Monthly allowance
(35,000 bits)

Create wallet backup

Bitcoin address #4
Private key #4

Change address
(0 bits)

Figure 2-2: A Bitcoin wallet is an organized collection of addresses and their corresponding private keys. Bitcoin wallet programs exist to help perform common tasks like sending
bitcoins and managing the bitcoins in your wallet.

Many Bitcoin wallet programs are available to choose from; most
are free downloads and can be run on your laptop or phone, or even in
your web browser. We’ll explore the various Bitcoin wallet programs in
Chapter 3, but in this chapter we’ll use the Electrum wallet, which is open
source, cross platform, and very simple to use.

GE T TING SOME “S TA R TE R MONE Y”
TO LE A RN A BOU T BITCOIN
You’ll need a small amount of Bitcoin (less than $1 USD) to work through this
chapter. If you have a friend who’s a bitcoiner, consider asking her to give you
a little change to use for practice. Otherwise, go to http://newbiecoins.com/,
which is a site we (the authors) will maintain as a public service and which will
list other sites that are giving away small amounts of free Bitcoin. There are usually some reputable sites giving out coins for newbies, but the situation for such
giveaways is fluid, with sites going up or down daily, so we can’t cover specific
ones in this book.

Bitcoin Basics

13

Creating Your First Bitcoin Wallet with Electrum
To follow along in this section, download and install Electrum (http://electrum
.org/). If you choose to use a different Bitcoin wallet program, most of the
instructions on the following pages should apply to it as well.
When you run Electrum the first time, you’ll be asked to create a new
wallet (or restore an old wallet, which we’ll ignore for now), as shown in
Figure 2-3.

Figure 2-3: Creating a new Bitcoin wallet with Electrum

The next step is specific to Electrum; that is, it is not a standard feature of most Bitcoin wallet programs. The application presents you with
a seed, which consists of 12 randomly chosen words, and asks you to write
them down (see Figure 2-4). Electrum uses this seed to create your Bitcoin
addresses and private keys; therefore, the seed must be kept secret, similar
to your private keys. Because we’ll be dealing with only small amounts of bitcoins in this chapter, you don’t need to be too careful just yet. However, you
should start keeping these security details in mind. A major benefit of a seed
is that if you lose your computer (say, in a fire or theft), everything—your
wallet, your Bitcoin address, your private keys, and (most importantly) your
money—can be recovered from the seed.
The next step gives you the option of creating a password. Although
the password is optional, it is very important. If your computer is stolen or
somehow falls into the wrong hands, the password prevents others from
spending your bitcoins. Because Electrum (and other Bitcoin wallet programs) uses the password to store your Bitcoin wallet on your computer in
an encrypted for