Blockchain in Action 9781617296338

There’s a lot more to the blockchain than mining Bitcoin. This secure system for registering and verifying ownership and

250 139 16MB

English Pages 352 Year 2020

Report DMCA / Copyright

DOWNLOAD FILE

Blockchain in Action
 9781617296338

Table of contents :
Blockchain in Action
Copyright
dedication
brief contents
contents
front matter
Preface
Acknowledgments
About this book
Who should read this book
How this book is organized: A roadmap
About the code
liveBook discussion forum
Other online resources
About the author
About the cover illustration
Part 1. Getting started with blockchain programming
1 Blockchain basics
1.1 From Bitcoin to blockchain
1.2 What is a blockchain?
1.3 Blockchain programming
1.3.1 Decentralized infrastructure
1.3.2 Distributed ledger technology
1.3.3 Disintermediation protocol
1.3.4 Trust enabler
1.4 Motivating scenarios
1.4.1 Automatic and consistent data collection
1.4.2 Timely information sharing
1.4.3 Verifiable compliance
1.4.4 Auditable actions for provenance
1.4.5 Guidance for governance
1.4.6 Attribution of actions
1.4.7 Pandemic management
1.5 Retrospective
1.6 Summary
2 Smart contracts
2.1 The concept of a smart contract
2.1.1 Bitcoin transactions versus smart contract transactions
2.1.2 What does a smart contract do?
2.2 Design of a smart contract
2.2.1 A use case diagram for the counter
2.2.2 Data assets, peer participants, roles, rules, and transactions
2.2.3 From class diagram to contract diagram
2.3 Development of a smart contract code
2.3.1 Solidity language
2.3.2 Smart contract code for Counter
2.4 Deploying and testing the smart contract
2.4.1 The Remix IDE
2.4.2 Deployment and testing
2.4.3 Key takeaways
2.5 What makes a blockchain contract smart?
2.6 Decentralized airline system use case
2.6.1 ASK definition
2.6.2 Sequence of operations
2.7 Airlines smart contract
2.7.1 Peer participants, data assets, roles, rules, and transactions
2.7.2 Airlines smart contract code
2.7.3 ASK smart contract deployment and testing
2.8 Smart contract design considerations
2.9 Best practices
2.10 Summary
3 Techniques for trust and integrity
3.1 Essentials of trust and integrity
3.1.1 Trust
3.1.2 Integrity
3.2 Digital democracy problem
3.2.1 Designing a solution
3.2.2 Use case diagram
3.2.3 Incremental development of code
3.2.4 Users, assets, and transactions
3.2.5 Finite state machine diagram
3.2.6 Trust intermediation
3.2.7 Defining and using modifiers
3.2.8 Contract diagram including modifiers
3.2.9 Putting it all together
3.3 Testing
3.3.1 Positive tests
3.3.2 Negative tests
3.4 Using modifiers, require(), and revert()
3.5 Assert() declarations
3.6 Best practices
3.7 Retrospective
3.8 Summary
4 From smart contracts to Dapps
4.1 Dapp development using Truffle
4.1.1 The development process
4.1.2 Installing Truffle
4.1.3 Building the Dapp stack
4.2 Install Ganache test chain
4.3 Develop the smart contract
4.3.1 Create a project folder
4.3.2 Add smart contract and compile
4.3.3 Configure blockchain network
4.3.4 Deploy the smart contract
4.4 Develop and configure the web application
4.4.1 Develop ballot-app
4.4.2 Launch the ballot-app
4.4.3 Install MetaMask wallet
4.4.4 Interact with Ballot-Dapp
4.4.5 Connect web client to smart contract
4.5 Retrospective
4.6 Best practices
4.7 Summary
Part 2. Techniques for end-to-end Dapp development
5 Security and privacy
5.1 Cryptography basics
5.1.1 Symmetric key cryptography
5.1.2 Asymmetric key cryptography
5.2 The relevance of public-key cryptography to blockchain
5.2.1 Generating Ethereum addresses
5.2.2 Transaction signing
5.2.3 Deploying smart contracts on Ropsten
5.2.4 Using the private key in mnemonic form
5.2.5 Populating a blockchain wallet
5.2.6 Deploying and transacting on Ropsten
5.3 Hashing basics
5.3.1 Digital signing of documents
5.3.2 Hashed data on distributed ledger
5.3.3 Hashes in Ethereum block header
5.3.4 Solidity hashing functions
5.4 Application of hashing
5.4.1 Blind auction design
5.4.2 Blind auction smart contract
5.4.3 Privacy and security aspects
5.4.4 Testing the BlindAuction contract
5.4.5 Test plan
5.5 Retrospective
5.6 Best practices
5.7 Summary
6 On-chain and off-chain data
6.1 On-chain data
6.2 Blind auction use case
6.2.1 On-chain event data
6.2.2 Blind auction with events
6.2.3 Testing with the web UI
6.2.4 Accessing on-chain data using the web3 API
6.3 Off-chain data: External data sources
6.4 ASK airline system
6.4.1 ASK concept
6.4.2 Airlines smart contract
6.4.3 ASK on-chain data
6.4.4 ASK off-chain data
6.4.5 ASK Dapp development process
6.4.6 ASK web user interface
6.4.7 Putting it all together
6.4.8 Interacting with ASK Dapp
6.5 Retrospective
6.6 Best practices
6.7 Summary
7 Web3 and a channel Dapp
7.1 Web3 API
7.1.1 Web3 in Dapp stack
7.1.2 Web3 packages
7.2 The channel concept
7.3 Micropayment channel
7.4 Micropayment channel use case
7.4.1 Traditional banking solution
7.4.2 Users and roles
7.4.3 On-chain and off-chain operations
7.4.4 MPC smart contract (MPC-contract)
7.4.5 MPC application development (MPC-app)
7.4.6 MPC sequence diagram
7.4.7 Demonstration of MPC execution
7.4.8 Accessing the web3 provider
7.4.9 Extensions of MPC
7.4.10 The relevance of the micropayment channel
7.4.11 Other web3 packages of interest
7.5 Retrospective
7.6 Best practices
7.7 Summary
8 Going public with Infura
8.1 Nodes and networks
8.2 Infura blockchain infrastructure
8.3 Going public with Infura
8.3.1 Blockchain node as a service
8.4 End-to-end process for public deployment
8.4.1 Account generation and management
8.4.2 Choosing a network and importing accounts
8.4.3 Collecting ether from faucets
8.4.4 Creating blockchain nodes on Infura
8.4.5 Installing HDWalletProvider
8.4.6 Configuring and deploying the smart contract
8.4.7 Configuring and deploying the web application
8.5 Deploying BlindAuction-Dapp on Infura
8.5.1 Setting up the blind auction environment
8.5.2 Decentralized participants
8.5.3 Configure and deploy the beneficiary account
8.5.4 Configure and deploy bidders
8.5.5 Interact with deployed blind auction Dapp
8.6 Deploying MPC-Dapp on Infura
8.6.1 Setting up the MPC environment
8.6.2 Configure and deploy the organizer
8.6.3 Configure and deploy the worker
8.7 Retrospective
8.8 Best practices
8.9 Summary
Part 3. A roadmap and the road ahead
9 Tokenization of assets
9.1 Ethereum standards
9.1.1 Ethereum improvement proposal
9.1.2 ERC20 token standard
9.1.3 Fungible and non-fungible tokens
9.2 RES4: Non-fungible real estate token
9.2.1 Use case diagram
9.2.2 Contract diagram
9.2.3 RES4 ERC721-compliant token
9.2.4 RES4 Dapp
9.2.5 Interaction with RES4 Dapp
9.3 Retrospective
9.4 Best practices
9.5 Summary
10 Testing smart contracts
10.1 Importance of testing smart contracts
10.1.1 Types of testing
10.1.2 Language choice for test programs
10.2 Testing counter smart contract
10.2.1 Writing counter test script
10.2.2 Positive and negative tests
10.2.3 Running the test script
10.3 Testing ballot smart contract
10.3.1 Writing the ballot test script
10.3.2 Executing the ballot test script
10.3.3 Describe() and it() test functions
10.4 Recap writing of test script
10.5 The blind auction test script
10.5.1 Analysis of describe() and it() code
10.5.2 Executing the blind auction test script
10.5.3 Full auction run
10.6 Retrospective
10.7 Best practices
10.8 Summary
11 A roadmap to Dapp development
11.1 Motivating scenario: Educational credentialing
11.2 The roadmap
11.3 Problem description
11.3.1 Context for the DCC application
11.3.2 Design choices
11.4 Analysis and design
11.4.1 Operation flow and finite state machine
11.4.2 Contract diagram
11.5 Developing the smart contract
11.5.1 Data structures
11.5.2 Events
11.5.3 Modifiers
11.5.4 Functions
11.6 Local deployment
11.7 Automated testing using truffle
11.8 Developing the web application
11.8.1 UI design
11.8.2 Coding the app.js
11.9 Testing the DCC-Dapp
11.10 Public deployment
11.10.1 Deployment on Ropsten-Infura
11.10.2 Create web-client for distribution
11.11 Retrospective
11.12 Best practices
Summary
12 Blockchain: The road ahead
12.1 Decentralized identity
12.2 Self-managed identity
12.3 Consensus and integrity
12.3.1 Proof of work
12.3.2 Proof of stake
12.3.3 Byzantine fault-tolerant consensus
12.4 Scalability
12.5 Scalability solutions
12.5.1 Side channel
12.5.2 Block size
12.5.3 Network speed
12.6 Privacy
12.7 Public, private, and permissioned networks
12.8 Confidentiality
12.8.1 Open information
12.8.2 A solution
12.9 Security
12.10 Securing it with cryptocurrency
12.11 Accessing off-chain data (Oracles)
12.12 From foundations to practical systems
12.13 Looking ahead
12.14 Best practices
12.15 Retrospective
12.16 Summary
appendix A. UML blockchain design models
A.1 Problem analysis and design
A.2 Behavioral diagrams
A.2.1 Use case diagrams
A.2.2 Finite state machine diagrams
A.3 Structural diagrams
A.3.1 Class diagrams
A.3.2 Classes and relationships
A.4 Interaction diagrams
appendix B. Design principles
index

Polecaj historie