Blockchain in Action

Book description

A blockchain is a collection of data records, or "blocks," that are linked through using secure cryptographic hashes to form a "chain" that can be read and verified easily by anyone with the correct credentials but cannot be altered. This system is perfect for supply chains, health records, and other sensitive data where security and transparency are critical. Blockchain in Action introduces the fundamental principles of the blockchain and teaches you to build secure applications that can be used for voting, private auctions, and electronic record management.

About the Technology
Blockchain is more than just the tech behind Bitcoin—much more! Combining impenetrable security, decentralized transactions, and independently verifiable supply chains, blockchain applications have transformed currency, digital identity, and logistics. Platforms such as Ethereum and Hyperledger make it easy to get started by using familiar programming languages.

About the Book
Blockchain in Action teaches you how to design and build blockchain-based decentralized apps, and is written in a clear, jargon-free style. First, you'll get an overview of how blockchain works. Next, you'll code your first smart contract using Ethereum and Solidity, adding a web interface, trust validation, and other features until your app is ready for deployment. The only thing you need to get started is standard hardware and open source software.

What's Inside
  • Blockchain compared with other distributed systems
  • Development in Solidity
  • Identity, privacy, and security
  • On-chain and off-chain data and operations


About the Reader
For programmers who know JavaScript.

About the Author
Bina Ramamurthy has thirty years of experience teaching distributed systems, data science, peer-to-peer networking, and blockchain.

Quotes
A terrific introduction to blockchain that takes you beyond the lingo to understand core concepts.
- Michael Jensen, Arcadia

Get a thorough understanding of decentralized systems and their part in your future design plans.
- Richard B. Ward, Principis Capital

Go from theory to practice to implementation with this excellent guide to navigating the blockchain maze.
- Sambasiva Andaluri, Amazon Web Services

A definitive source on blockchain and one of the few books that covers blockchain practically.
- M. Sheik Uduman Ali. Harman Connected Services

Table of contents

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

Product information

  • Title: Blockchain in Action
  • Author(s): Bina Ramamurthy
  • Release date: October 2020
  • Publisher(s): Manning Publications
  • ISBN: 9781617296338