Blockchain Development with Hyperledger

Book Description

Learn quick and effective techniques for developing blockchain-based distributed ledgers with ease

Key Features

  • Discover why blockchain is a game changer in the technology landscape
  • Set up blockchain networks using Hyperledger Fabric
  • Write smart contracts at speed with Hyperledger Composer

Book Description

Blockchain and Hyperledger are open source technologies that power the development of decentralized applications. This Learning Path is your helpful reference for exploring and building blockchain networks using Ethereum, Hyperledger Fabric, and Hyperledger Composer.

Blockchain Development with Hyperledger will start off by giving you an overview of blockchain and demonstrating how you can set up an Ethereum development environment for developing, packaging, building, and testing campaign-decentralized applications. You'll then explore the de facto language Solidity, which you can use to develop decentralized applications in Ethereum. Following this, you'll be able to configure Hyperledger Fabric and use it to build private blockchain networks and applications that connect to them. Toward the later chapters, you'll learn how to design and launch a network, and even implement smart contracts in chain code. By the end of this Learning Path, you'll be able to build and deploy your own decentralized applications by addressing the key pain points encountered in the blockchain life cycle.

This Learning Path includes content from the following Packt products:

  • Blockchain Quick Start Guide by Xun (Brian) Wu and Weimin Sun
  • Hands-On Blockchain with Hyperledger by Nitin Gaur et al.

What you will learn

  • Understand why decentralized applications are necessary
  • Develop and test a decentralized application with Hyperledger Fabric and Hyperledger Composer
  • Write and test a smart contract using Solidity
  • Design transaction models and chain code with Golang
  • Deploy the Composer REpresentational State Transfer (REST) Gateway to access Composer transactions
  • Maintain, monitor, and manage your blockchain solutions

Who this book is for

This Learning Path is designed for blockchain developers who want to build decentralized applications and smart contracts from scratch using Hyperledger. Basic familiarity with or exposure to any programming language will be useful to get started with this course.

Publisher Resources

Download Example Code

Table of Contents

  1. Title Page
  2. Copyright
    1. Blockchain Development with Hyperledger
  3. About Packt
    1. Why Subscribe?
    2. Packt.com
  4. Contributors
    1. About the Authors
    2. Packt Is Searching for Authors Like You
  5. Preface
    1. Who This Book Is For
    2. What This Book Covers
    3. To Get the Most out of This Book
      1. Download the Example Code Files
      2. Conventions Used
    4. Get in Touch
      1. Reviews
  6. Blockchain - Enterprise and Industry Perspective
    1. Defining the terms – what is a blockchain?
    2. Four core building blocks of blockchain framworks
      1. Additional capabilities to consider
    3. Fundamentals of the secure transaction processing protocol
    4. Where blockchain technology has been and where it's going
      1. The great divide
      2. An economic model for blockchain delivery
      3. Learning as we go
      4. The promise of trust and accountability
    5. Industries putting blockchain technology to work
    6. Blockchain in the enterprise
      1. What applications are a good fit?
      2. How does the enterprise view blockchain?
      3. Litmus testing to justify the application of blockchain technology
      4. Integrating a blockchain infrastructure for the whole enterprise
    7. Enterprise design principles
      1. Business drivers and evolution
      2. Ensuring sustainability
      3. The principles that drive blockchain adoption
    8. Business considerations for choosing a blockchain framework
    9. Technology considerations for choosing a blockchain framework
      1. Identity management
      2. Scalability
      3. Enterprise security
      4. Development tooling
      5. Crypto-economic models
      6. Decentralization with systemic governance
      7. Enterprise support
      8. Use case-driven pluggability choices
        1. Shared ledger technology
        2. Consensus
        3. Crypto algorithms and encryption technology
        4. Use case-driven pluggable choices
    10. Enterprise integration and designing for extensibility
    11. Other considerations
      1. Consensus, ACID property, and CAP
        1. CAP
        2. ACID
      2. Attestation – SSCs are signed and encrypted
      3. Use of HSMs
    12. Summary
  7. Exploring Hyperledger Fabric
    1. Hyperledger frameworks, tools, and building blocks
      1. Hyperledger frameworks
      2. Hyperledger tools
      3. The building blocks of blockchain solutions
    2. Hyperledger Fabric component design
      1. Principles of Hyperledger design
      2. CAP Theorem
      3. Hyperledger Fabric reference architecture
      4. Hyperledger Fabric runtime architecture
      5. Strengths and advantages of a componentized design
    3. Hyperledger Fabric – the journey of a sample transaction
    4. Hyperledger Fabric explored
      1. Components in a blockchain network
      2. Developer interaction
    5. Understanding governance in business networks powered by blockchain
      1. Governance structure and landscape
      2. Information technology governance
      3. Blockchain network governance
      4. Business network governance
    6. Summary
  8. Setting the Stage with a Business Scenario
    1. Trading and letter of credit
      1. The importance of trust in facilitating trade
      2. The letter of credit process today
    2. Business scenario and use case
      1. Overview
      2. Real-world processes
      3. Simplified and modified processes
      4. Terms used in trade finance and logistics
      5. Shared process workflow
      6. Shared assets and data
      7. Participants' roles and capabilities
      8. Benefits of blockchain applications over current real-world processes
    3. Setting up the development environment
      1. Designing a network
      2. Installing prerequisites
      3. Forking and cloning the trade-finance-logistics repository
      4. Creating and running a network configuration 
        1. Preparing the network
        2. Generating network cryptographic material
        3. Generating channel artifacts
        4. Generating the configuration in one operation
        5. Composing a sample trade network
    4. Network components' configuration files
    5. Launching a sample trade network
    6. Summary
  9. Designing a Data and Transaction Model with Golang
    1. Starting the chaincode development
      1. Compiling and running chaincode
      2. Installing and instantiating chaincode
      3. Invoking chaincode
    2. Creating a chaincode
      1. The chaincode interface
      2. Setting up the chaincode file
        1. The Invoke method
    3. Access control
      1. ABAC
        1. Registering a user
        2. Enrolling a user
        3. Retrieving user identities and attributes in chaincode
    4. Implementing chaincode functions
      1. Defining chaincode assets
      2. Coding chaincode functions
      3. Creating an asset
      4. Reading and modifying an asset
      5. Main function
    5. Testing chaincode
      1. SHIM mocking
        1. Testing the Init method
        2. Testing the Invoke method
        3. Running tests
    6. Chaincode design topics
      1. Composite keys
      2. Range queries
      3. State queries and CouchDB
      4. Indexes
      5. ReadSet and WriteSet
      6. Multiversion concurrency control
    7. Logging output
      1. Configuration
      2. Logging API
      3. SHIM logging levels
      4. Stdout and stderr
      5. Additional SHIM API functions
    8. Summary
  10. Exposing Network Assets and Transactions
    1. Building a complete application
      1. The nature of a Hyperledger Fabric application
        1. Application and transaction stages
        2. Application model and architecture
      2. Building the application
      3. Middleware – wrapping and driving the chaincode
        1. Installation of tools and dependencies
          1. Prerequisites for creating and running the middleware
          2. Installation of dependencies
        2. Creating and running the middleware
          1. Network configuration
          2. Endorsement policy
          3. User records
          4. Client registration and enrollment
          5. Creating a channel
          6. Joining a channel
          7. Installation of chaincode
          8. Instantiation of chaincode
          9. Invoking the chaincode
          10. Querying the chaincode
          11. Completing the loop – subscribing to blockchain events
          12. Putting it all together
      4. User application – exporting the service and API
        1. Applications
        2. User and session management
        3. Designing an API
        4. Creating and launching a service
          1. User and session management
          2. Network administration
          3. Exercising the application
          4. User/client interaction modes
        5. Testing the Middleware and Application
    2. Integration with existing systems and processes
      1. Design considerations
      2. Decentralization
      3. Process alignment
        1. Message affinity
      4. Service discovery
      5. Identity mapping
      6. Integration design pattern
        1. Enterprise system integration
        2. Integrating with an existing system of record
        3. Integrating with an operational data store
        4. Microservice and event-driven architecture
      7. Considering reliability, availability, and serviceability
        1. Reliability
        2. Availability
        3. Serviceability
    3. Summary
  11. Business Networks
    1. A busy world of purposeful activity
      1. Why a language for business networks?
    2. Defining business networks
      1. A deeper idea
    3. Introducing participants
      1. Types of participant
        1. Individual participants
        2. Organizational participants
        3. System or device participants
      2. Participants are agents
      3. Participants and identity
    4. Introducing assets
      1. Assets flow between participants
      2. Tangible and intangible assets
      3. The structure of assets
      4. Ownership is a special relationship
      5. Asset life cycles
      6. Describing asset's life cycles in detail with transactions
    5. Introducing transactions
      1. Change as a fundamental concept
      2. Transaction definition and instance
      3. Implicit and explicit transactions
      4. The importance of contracts
      5. Signatures
      6. Smart contracts for multi-party transaction processing
      7. Digital transaction processing
      8. Initiating transactions
      9. Transaction history
      10. Transaction streams
      11. Separating transactions into different business networks
      12. Transaction history and asset states
      13. A business network as a history of transactions
      14. Regulators and business networks
    6. Discussing events from the perspective of designing a business network using Composer
      1. A universal concept
      2. Messages carry event notifications
      3. An example to illustrate event structure
      4. Events and transactions
      5. External versus explicit events
      6. Events cause participants to act
      7. Loosely coupled design
      8. The utility of events
    7. Implementing a business network
      1. The importance of de-materialization
      2. Blockchain benefits for B2B and EDI
      3. Participants that interact with the blockchain
      4. Accessing the business network with APIs
      5. A 3-tier systems architecture
      6. Hyperledger Fabric and Hyperledger Composer
    8. Summary
  12. A Business Network Example
    1. The letter of credit sample
      1. Installing the sample
      2. Running the sample
        1. Step 1 – preparing to request a letter of credit
        2. Step 2 – requesting a letter of credit
        3. Step 3 – importing bank approval
        4. Step 4 – exporting bank approval
        5. Step 5 – letter received by exporter
        6. Step 6 – shipment
        7. Step 7 – goods received
        8. Step 8 – payment
        9. Step 9 – closing the letter
        10. Step 10 – Bob receives payment
      3. Recapping the process
    2. Analyzing the letter of credit process
      1. The Playground
      2. Viewing the business network
    3. A description of the business network
      1. The participant descriptions
      2. The asset descriptions
      3. The transaction descriptions
      4. The event descriptions
    4. A model of the business network
      1. Namespaces
      2. Enumerations
      3. Asset definitions
      4. Participant definitions
      5. Concept definitions
      6. Transaction definitions
      7. Event definitions
    5. Examining the live network
      1. Examining a letter of credit instance
      2. Examining participant instances
      3. Examining transaction instances
      4. Submitting a new transaction to the network
      5. Understanding how transactions are implemented
    6. Creating business network APIs
      1. SWAGGER API definitions
      2. Querying the network using SWAGGER
      3. Testing the network from the command line
      4. Creating a new letter using SWAGGER
      5. Network cards and wallets
      6. Access-control lists
    7. Summary
  13. Agility in a Blockchain Network
    1. Defining the promotion process
      1. Smart contract considerations
      2. Integration layer considerations
      3. Promotion process overview
    2. Configuring a continuous integration pipeline
      1. Customizing the pipeline process
        1. Local build
        2. Configuring Travis CI
        3. Customizing the pipeline using .travis.yml
      2. Publishing our smart contract package
    3. Configuring your Git repository
      1. Setting the code owners of our smart contract
        1. Sample content of the CODEOWNERS
      2. Protecting the master branch
      3. Configuring Git for commit signing and validation
        1. Configuring GPG on your local workstation
    4. Testing the end-to-end process
      1. Creating a new transaction
        1. Pushing a commit to the master branch directly
        2. Submitting a pull request with an unsigned commit
      2. Adding test cases
        1. Submitting a pull request with a signed commit
        2. Adding the mergeAssets unit test
      3. Releasing the new version
    5. Updating the network
      1. Notifying the consortium
      2. Upgrading the business network
        1. Downloading a new version
        2. Updating the business network
    6. Summary
  14. Life in a Blockchain Network
    1. Modifying or upgrading a Hyperledger Fabric application
      1. Fabric blockchain and application life cycle
      2. Channel configuration updates
        1. Prerequisites for adding a new organization to the network
        2. Generating network cryptographic material
        3. Generating channel artifacts
        4. Generating the configuration and network components in one operation
        5. Launching the network components for the new organization
        6. Updating the channel configuration
        7. Adding the new organization to the network
      3. Smart contract and policy updates
        1. Modification in chaincode logic
        2. Dependency upgrades in chaincode
        3. Ledger resetting
        4. Endorsement policy update
        5. Upgrading chaincode and endorsement policy on the trade channel
      4. Platform upgrades
    2. System monitoring and performance
      1. Measurement and analytics
      2. What should we measure or understand in a Fabric application
        1. Blockchain applications vis-à-vis traditional transaction processing applications
        2. Metrics for performance analysis
      3. Measurement and data collection in a Fabric application
        1. Collecting health and capacity information
        2. Profiling containers and applications
        3. Measuring application performance
      4. Fabric engineering guidelines for performance
        1. Platform performance characteristics
        2. System bottlenecks
        3. Configuration and tuning
        4. Ledger data availability and caching
          1. Redundant committing peer
          2. Data caching
        5. Fabric performance measurement and benchmarking
    3. Summary
  15. Governance, Necessary Evil of Regulated Industries
    1. Decentralization and governance
    2. Exploring the business models
      1. Blockchain benefits
        1. Supply chain management
        2. Healthcare
        3. Finance – letter of credit
      2. From benefits to profits
      3. Network business model
        1. Founder-led network
        2. Consortium-based network
        3. Community-based network
        4. Hybrid models
          1. Joint venture
          2. New corporation
    3. Role of governance in a business network
    4. Business domains and processes
      1. Membership life cycle
      2. Funding and fees
      3. Regulation
      4. Education
      5. Service life cycle
      6. Disputes
    5. Governance structure
      1. Centralized governance
        1. Strategic governance
        2. Operational governance
        3. Tactical governance
      2. Decentralized governance
    6. Governance and the IT solution
      1. Managed on-boarding
    7. Summary
  16. Hyperledger Fabric Security
    1. Hyperledger Fabric design goals impacting security
    2. Hyperledger Fabric architecture 
      1. Fabric CA or membership service provider
      2. Peer
      3. Smart contract or chaincode
      4. Ledger
      5. Private data
      6. Ordering service
    3. Network bootstrap and governance – the first step towards security
      1. Creating the network
      2. Adding new members
      3. Deploying and updating chaincode 
      4. Data model
    4. Strong identities – the key to the security of the Hyperledger Fabric network
      1. Bootstrapping Fabric CA
        1. Register
        2. Default Fabric roles 
        3. Enroll
          1. Which crypto protocols are allowed in certificate signing requests?
        4. Revoking identities 
      2. Practical considerations in managing users in Fabric CA
    5. Chaincode security
      1. How is chaincode shared with other endorsing peers?
      2. Who can install chaincode?
      3. Chaincode encryption
      4. Attribute-based access control
        1. Pros and cons of attribute-based access control
    6. Common threats and how Hyperledger Fabric mitigates them 
      1. Transaction privacy in Hyperledger Fabric
        1. Channels
        2. Private data
        3. Encrypting transaction data
    7. Hyperledger Fabric and Quantum Computing
    8. General data protection regulation (GDPR) considerations
    9. Summary
  17. Introduction to Blockchain Technology
    1. The genealogy analogy
      1. Bitcoin
      2. Why Bitcoin
      3. A peer-to-peer network
      4. Cryptography and hash functions
      5. The distributed ledger, blocks, transactions, addresses, and UTXO
    2. The consensus mechanism
      1. Forking
      2. Mining and difficulty level
      3. Hacking – the 51% problem
      4. Private keys and Bitcoin wallets
      5. Bitcoin scripting
      6. Altcoins
      7. Ethereum
    3. Enterprise blockchain – Hyperledger
    4. The evolution of blockchain
    5. Summary
  18. Ethereum Fundamentals
    1. An overview of Ethereum
    2. Ethereum basic concepts
      1. Ether
      2. ERC20 tokens
      3. Smart contracts
      4. Ethereum virtual machines
      5. Ethereum gas
      6. Account
      7. Oracle
      8. Other concepts
    3. Performance
      1. Throughput
      2. Proof-of-Stake (PoS)
      3. Casper
      4. Plasma
      5. Sharding
    4. Summary
  19. Overview of Solidity Programming
    1. What is solidity?
    2. Tools for solidity development environment
      1. Browser-based IDE
        1. Remix
        2. EthFiddle
      2. Command-line development management tools
        1. Truffle
    3. Introduction to smart contracts
      1. Layout of a solidity source file
        1. Pragma
        2. Comments
        3. Import
        4. Paths
        5. Relative paths
      2. Structure of a contract
        1. State variables
        2. Data type
        3. Enum type
        4. Struct type
        5. Mapping
        6. Functions
        7. Input parameters
        8. Access modifiers
        9. Output parameters
        10. Modifiers
        11. Events
        12. Constructor
        13. Constant state variables, unit, and functions
          1. Ether units
          2. Time units
      3. Inheritance, abstract, and interface
    4. Common smart contract patterns
      1. Access restriction
      2. State machine
    5. Smart contract security
      1. Keep contract simple and modular
      2. Use the checks-effects-interactions pattern
      3. DoS with block gas limit
      4. Handle errors in external calls
    6. Case study – crowdfunding campaign
    7. Summary
  20. Building an Ethereum Blockchain Application
    1. Decentralized application overview
      1. web3.js quick overview
      2. Provider
    2. DApp development tools
      1. Truffle
      2. Ganache
    3. Setting up an Ethereum development environment
      1. Installing Truffle
      2. Installing Ganache
      3. Creating a Truffle project
        1. Launching the Ganache environment
    4. Deploying a smart contract
    5. Writing a campaign decentralized application
      1. Selecting a web3 provider
      2. Loading account information
      3. Loading project information
      4. Handling the fund function
      5. checkGoalReached
    6. Summary
  21. Exploring an Enterprise Blockchain Application Using Hyperledger Fabric
    1. Issuance claim
    2. Setting up a Hyperledger Fabric environment
      1. Installation prerequisites
      2. Installing Hyperledger Fabric
    3. Writing chaincode
      1. Development tools
        1. LiteIDE 
        2. JetBrains Gogland
        3. Visual Studio Code
      2. Chaincode key concept and APIs
      3. Defining an issuance claim
      4. Initializing the chaincode
      5. Invoking the chaincode
      6. AddCompany
      7. ReportLost
      8. RequestedInfo
      9. SubmitClaim, ConfirmClaimSubmission, ApproveClaim
        1. Query
        2. getHistory
    4. Configuring Hyperledger Fabric
      1. Generating the certificate
      2. Generating an orderer genesis block
      3. Generating a channel configuration transaction
      4. Overview of Hyperledger Fabric Docker composer configuration files
      5. Fabric project directory structure
      6. Docker-compose-base.yaml
      7. Peer-base.yaml
      8. Starting the Hyperledger Fabric network
      9. Creating a channel
      10. Joining channels
      11. Updating the anchor
      12. Installing chaincode
      13. Instantiating the chaincode
      14. Invoking add broker
      15. Invoking add insurer
      16. Invoking ReportLost
      17. Invoking RequestedInfo
      18. Invoking SubmitClaim
      19. Invoking ConfirmClaimSubmission
      20. Invoking ApproveClaim
      21. Querying claim history
      22. End-to-end test execution 
    5. Summary
  22. Implementing Business Networks Using Hyperledger Composer
    1. Hyperledger Composer – a quick overview
      1. Yeoman generator
      2. Composer REST server
      3. LoopBack connector
      4. JavaScript SDK
      5. Composer playground
      6. Composer-cli
    2. Setting up a Hyperledger Composer environment
      1. Installation prerequisites
      2. Installing the development environment
    3. Analyzing business scenarios
    4. Business network archive
      1. Network model file (.cto)
      2. Script file (.js)
      3. Access control list (ACL) file (.acl)
      4. Query file (.qry)
      5. Designing business models
    5. Implementing the business transaction function
      1. Testing in the playground
      2. Deploying a business network
      3. Integrating with REST server
      4. Generating the Hyperledger Composer REST API
    6. Summary
  23. Blockchain Use Cases
    1. Blockchain use case examples
      1. Payment and settlement services
      2. Import and export finance
      3. Immutable ledger
      4. Regulatory compliance and auditing
      5. Identity theft detection
      6. Funds back-office operation
      7. Collateral management
      8. Healthcare systems
      9. Real estate trading and rental markets
      10. IP market
      11. Elections
      12. HR and recruiting
      13. Public records
      14. Reduce contract disputes
      15. Sharing economy
      16. Integration with IoT
      17. Facilitate commercial and social relationships
    2. How to choose a proper use case
    3. DApp use case – healthcare data sharing
      1. The business problem
      2. A blockchain solution
    4. Summary
  24. Other Books You May Enjoy
    1. Leave a Review - Let Other Readers Know What You Think

Product Information

  • Title: Blockchain Development with Hyperledger
  • Author(s): Salman A. Baset, Luc Desrosiers, Nitin Gaur, Petr Novotny
  • Release date: March 2019
  • Publisher(s): Packt Publishing
  • ISBN: 9781838649982