Preface |
|
xv | |
Acknowledgments |
|
xvii | |
About this book |
|
xviii | |
About the author |
|
xxii | |
About the cover illustration |
|
xxiii | |
|
Part 1 Getting started with blockchain programming |
|
|
1 | (102) |
|
|
3 | (19) |
|
1.1 From Bitcoin to blockchain |
|
|
4 | (2) |
|
1.2 What is a blockchain? |
|
|
6 | (2) |
|
1.3 Blockchain programming |
|
|
8 | (8) |
|
Decentralized infrastructure |
|
|
8 | (3) |
|
Distributed ledger technology |
|
|
11 | (3) |
|
Disintermediation protocol |
|
|
14 | (1) |
|
|
15 | (1) |
|
|
16 | (3) |
|
Automatic and consistent data collection |
|
|
17 | (1) |
|
Timely information sharing |
|
|
17 | (1) |
|
|
18 | (1) |
|
Auditable actions for provenance |
|
|
18 | (1) |
|
|
18 | (1) |
|
|
18 | (1) |
|
|
19 | (1) |
|
|
19 | (1) |
|
|
20 | (2) |
|
|
22 | (32) |
|
2.1 The concept of a smart contract |
|
|
23 | (2) |
|
Bitcoin transactions versus smart contract transactions |
|
|
24 | (1) |
|
What does a smart contract do? |
|
|
25 | (1) |
|
2.2 Design of a smart contract |
|
|
25 | (5) |
|
A use case diagram for the counter |
|
|
26 | (1) |
|
Data assets, peer participants, roles, rules, and transactions |
|
|
27 | (1) |
|
From class diagram to contract diagram |
|
|
28 | (2) |
|
2.3 Development of a smart contract code |
|
|
30 | (2) |
|
|
30 | (1) |
|
Smart contract code for Counter |
|
|
30 | (2) |
|
2.4 Deploying and testing the smart contract |
|
|
32 | (4) |
|
|
32 | (2) |
|
|
34 | (1) |
|
|
35 | (1) |
|
2.5 What makes a blockchain contract smart? |
|
|
36 | (2) |
|
2.6 Decentralized airline system use case |
|
|
38 | (3) |
|
|
38 | (1) |
|
|
39 | (2) |
|
2.7 Airlines smart contract |
|
|
41 | (11) |
|
Peer participants, data assets, roles, rules, and transactions |
|
|
42 | (2) |
|
Airlines smart contract code |
|
|
44 | (2) |
|
ASK smart contract deployment and testing |
|
|
46 | (6) |
|
2.8 Smart contract design considerations |
|
|
52 | (1) |
|
|
52 | (1) |
|
|
53 | (1) |
|
3 Techniques for trust and integrity |
|
|
54 | (25) |
|
3.1 Essentials of trust and integrity |
|
|
55 | (3) |
|
|
55 | (2) |
|
|
57 | (1) |
|
3.2 Digital democracy problem |
|
|
58 | (12) |
|
|
58 | (1) |
|
|
58 | (1) |
|
Incremental development of code |
|
|
59 | (1) |
|
Users, assets, and transactions |
|
|
60 | (2) |
|
Finite state machine diagram |
|
|
62 | (2) |
|
|
64 | (1) |
|
Defining and using modifiers |
|
|
65 | (1) |
|
Contract diagram including modifiers |
|
|
66 | (1) |
|
|
67 | (3) |
|
|
70 | (3) |
|
|
71 | (1) |
|
|
72 | (1) |
|
3.4 Using modifiers, require(), and revert() |
|
|
73 | (1) |
|
3.5 Assert() declarations |
|
|
74 | (2) |
|
|
76 | (1) |
|
|
77 | (1) |
|
|
77 | (2) |
|
4 From smart contracts to Dapps |
|
|
79 | (24) |
|
4.1 Dapp development using Truffle |
|
|
81 | (4) |
|
|
82 | (1) |
|
|
82 | (2) |
|
|
84 | (1) |
|
4.2 Install Ganache test chain |
|
|
85 | (1) |
|
4.3 Develop the smart contract |
|
|
86 | (5) |
|
|
87 | (2) |
|
Add smart contract and compile |
|
|
89 | (1) |
|
Configure blockchain network |
|
|
90 | (1) |
|
Deploy the smart contract |
|
|
90 | (1) |
|
4.4 Develop and configure the web application |
|
|
91 | (9) |
|
|
92 | (2) |
|
|
94 | (1) |
|
|
95 | (2) |
|
Interact with Ballot-Dapp |
|
|
97 | (2) |
|
Connect web client to smart contract |
|
|
99 | (1) |
|
|
100 | (1) |
|
|
101 | (1) |
|
|
102 | (1) |
|
Part 2 Techniques for end-to-end Dapp development |
|
|
103 | (122) |
|
|
105 | (24) |
|
|
107 | (2) |
|
Symmetric key cryptography |
|
|
107 | (1) |
|
Asymmetric key cryptography |
|
|
108 | (1) |
|
5.2 The relevance of public-key cryptography to blockchain |
|
|
109 | (7) |
|
Generating Ethereum addresses |
|
|
109 | (1) |
|
|
110 | (1) |
|
Deploying smart contracts on Ropsten |
|
|
110 | (1) |
|
Using the private key in mnemonic form |
|
|
111 | (1) |
|
Populating a blockchain wallet |
|
|
112 | (1) |
|
Deploying and transacting on Ropsten |
|
|
113 | (3) |
|
|
116 | (3) |
|
Digital signing of documents |
|
|
117 | (1) |
|
Hashed data on distributed ledger |
|
|
117 | (1) |
|
Hashes in Ethereum block header |
|
|
117 | (1) |
|
Solidity hashing functions |
|
|
118 | (1) |
|
5.4 Application of hashing |
|
|
119 | (8) |
|
|
119 | (1) |
|
Blind auction smart contract |
|
|
120 | (1) |
|
Privacy and security aspects |
|
|
121 | (3) |
|
Testing the BlindAuction contract |
|
|
124 | (1) |
|
|
125 | (2) |
|
|
127 | (1) |
|
|
127 | (1) |
|
|
127 | (2) |
|
6 On-chain and off-chain data |
|
|
129 | (33) |
|
|
131 | (2) |
|
6.2 Blind auction use case |
|
|
133 | (12) |
|
|
133 | (1) |
|
Blind auction with events |
|
|
134 | (4) |
|
|
138 | (6) |
|
Accessing on-chain data using the web3 API |
|
|
144 | (1) |
|
6.3 Off-chain data: External data sources |
|
|
145 | (1) |
|
|
146 | (13) |
|
|
147 | (3) |
|
|
150 | (2) |
|
|
152 | (1) |
|
|
153 | (1) |
|
ASKDapp development process |
|
|
153 | (1) |
|
|
154 | (2) |
|
|
156 | (1) |
|
|
156 | (3) |
|
|
159 | (1) |
|
|
160 | (1) |
|
|
161 | (1) |
|
7 Web3 and a channel Dapp |
|
|
162 | (31) |
|
|
163 | (3) |
|
|
163 | (2) |
|
|
165 | (1) |
|
|
166 | (1) |
|
|
167 | (1) |
|
7.4 Micropayment channel use case |
|
|
168 | (23) |
|
Traditional banking solution |
|
|
169 | (3) |
|
|
172 | (1) |
|
On-chain and off-chain operations |
|
|
173 | (2) |
|
MPC smart contract (MPC-contract) |
|
|
175 | (3) |
|
MPC application development (MPC-app) |
|
|
178 | (3) |
|
|
181 | (1) |
|
Demonstration of MPC execution |
|
|
182 | (5) |
|
Accessing the web 3 provider |
|
|
187 | (2) |
|
|
189 | (1) |
|
The relevance of the micropayment channel |
|
|
190 | (1) |
|
Other web3 packages of interest |
|
|
190 | (1) |
|
|
191 | (1) |
|
|
191 | (1) |
|
|
192 | (1) |
|
8 Going public with Infura |
|
|
193 | (32) |
|
|
194 | (1) |
|
8.2 Infura blockchain infrastructure |
|
|
195 | (1) |
|
8.3 Going public with Infura |
|
|
196 | (2) |
|
Blockchain node as a service |
|
|
196 | (2) |
|
8.4 End-to-end process for public deployment |
|
|
198 | (8) |
|
Account generation and management |
|
|
199 | (1) |
|
Choosing a network and importing accounts |
|
|
200 | (1) |
|
Collecting ether from faucets |
|
|
201 | (2) |
|
Creating blockchain nodes on Infura |
|
|
203 | (1) |
|
Installing HDWalletProvider |
|
|
204 | (1) |
|
Configuring and deploying the smart contract |
|
|
204 | (1) |
|
Configuring and deploying the web application |
|
|
205 | (1) |
|
8.5 Deploying BlindAuction-Dapp on Infura |
|
|
206 | (9) |
|
Setting up the blind auction environment |
|
|
206 | (1) |
|
Decentralized participants |
|
|
207 | (1) |
|
Configure and deploy the beneficiary account |
|
|
208 | (3) |
|
Configure and deploy bidders |
|
|
211 | (1) |
|
Interact with deployed blind auction Dapp |
|
|
212 | (3) |
|
8.6 Deploying MPC-Dapp on Infura |
|
|
215 | (7) |
|
Setting up the MPC environment |
|
|
215 | (2) |
|
Configure and deploy the organizer |
|
|
217 | (3) |
|
Configure and deploy the worker |
|
|
220 | (2) |
|
|
222 | (1) |
|
|
222 | (1) |
|
|
223 | (2) |
|
Part 3 A roadmap and the road ahead |
|
|
225 | (88) |
|
|
227 | (22) |
|
|
228 | (5) |
|
Ethereum improvement proposal |
|
|
229 | (1) |
|
|
229 | (2) |
|
Fungible and non-fungible tokens |
|
|
231 | (2) |
|
9.2 RES4: Non-fungible real estate token |
|
|
233 | (13) |
|
|
233 | (1) |
|
|
234 | (1) |
|
RES4 ERC721-compliant token |
|
|
235 | (2) |
|
|
237 | (2) |
|
Interaction with RES4 Dapp |
|
|
239 | (7) |
|
|
246 | (1) |
|
|
247 | (1) |
|
|
247 | (2) |
|
10 Testing smart contracts |
|
|
249 | (18) |
|
10.1 Importance of testing smart contracts |
|
|
250 | (1) |
|
|
250 | (1) |
|
Language choice for test programs |
|
|
251 | (1) |
|
10.2 Testing counter smart contract |
|
|
251 | (6) |
|
Writing counter test script |
|
|
252 | (3) |
|
Positive and negative tests |
|
|
255 | (1) |
|
|
255 | (2) |
|
10.3 Testing ballot smart contract |
|
|
257 | (3) |
|
Writing the ballot test script |
|
|
257 | (1) |
|
Executing the ballot test script |
|
|
258 | (1) |
|
Describe() and it() test functions |
|
|
259 | (1) |
|
10.4 Recap writing of test script |
|
|
260 | (1) |
|
10.5 The blind auction test script |
|
|
260 | (5) |
|
Analysis of describe() and it() code |
|
|
262 | (1) |
|
Executing the blind auction test script |
|
|
263 | (1) |
|
|
264 | (1) |
|
|
265 | (1) |
|
|
265 | (1) |
|
|
266 | (1) |
|
11 Roadmap to Dapp development |
|
|
267 | (25) |
|
11.1 Motivating scenario: Educational credentialing |
|
|
268 | (1) |
|
|
269 | (1) |
|
|
270 | (2) |
|
Context for the DCC application |
|
|
270 | (1) |
|
|
271 | (1) |
|
|
272 | (2) |
|
Operation flow and finite state machine |
|
|
272 | (1) |
|
|
273 | (1) |
|
11.5 Developing the smart contract |
|
|
274 | (6) |
|
|
274 | (1) |
|
|
274 | (1) |
|
|
275 | (1) |
|
|
275 | (5) |
|
|
280 | (1) |
|
11.7 Automated testing using truffle |
|
|
280 | (2) |
|
11.8 Developing the web application |
|
|
282 | (3) |
|
|
283 | (2) |
|
|
285 | (1) |
|
11.9 Testing the DCC-Dapp |
|
|
285 | (1) |
|
|
286 | (4) |
|
Deployment on Ropsten-Infura |
|
|
287 | (2) |
|
Create web-client for distribution |
|
|
289 | (1) |
|
|
290 | (1) |
|
|
290 | (1) |
|
|
291 | (1) |
|
12 Blockchain: The road ahead |
|
|
292 | (21) |
|
12.1 Decentralized identity |
|
|
293 | (1) |
|
12.2 Self-managed identity |
|
|
293 | (3) |
|
12.3 Consensus and integrity |
|
|
296 | (2) |
|
|
297 | (1) |
|
|
297 | (1) |
|
Byzantine fault-tolerant consensus |
|
|
298 | (1) |
|
|
298 | (1) |
|
12.5 Scalability solutions |
|
|
299 | (1) |
|
|
299 | (1) |
|
|
300 | (1) |
|
|
300 | (1) |
|
|
300 | (1) |
|
12.7 Public, private, and permissioned networks |
|
|
300 | (2) |
|
|
302 | (1) |
|
|
302 | (1) |
|
|
303 | (1) |
|
|
303 | (2) |
|
12.10 Securing it with cryptocurrency |
|
|
305 | (1) |
|
12.11 Accessing off-chain data (Oracles) |
|
|
306 | (1) |
|
12.12 From foundations to practical systems |
|
|
307 | (2) |
|
|
309 | (1) |
|
|
310 | (1) |
|
|
310 | (1) |
|
|
311 | (2) |
Appendix A UML blockchain design models |
|
313 | (8) |
Appendix B Design principles |
|
321 | (2) |
Index |
|
323 | |