Hyperledger Cookbook: Over 40 recipes implementing the latest Hyperledger blockchain frameworks and tools
()
About this ebook
Explore the entire Hyperledger blockchain family, including frameworks such as Fabric, Sawtooth, Indy, Burrow, and Iroha; and tools such as Composer, Explorer, and Caliper.
Key Features
- Plan, design, and create a full-fledged private decentralized application using Hyperledger services
- Master the ins and outs of the Hyperledger network using real-world examples
- Packed with problem-solution-based recipes to tackle pain areas in the blockchain development cycle
Book Description
Hyperledger is an open-source project and creates private blockchain applications for a range of domains. This book will be your desk reference as you explore common and not-so-common challenges faced while building blockchain networks using Hyperledger services.
We'll work through all Hyperledger platform modules to understand their services and features and build end-to-end blockchain applications using various frameworks and tools supported by Hyperledger. This book's independent, recipe-based approach (packed with real-world examples) will familiarize you with the blockchain development cycle. From modeling a business network to integrating with various tools, you will cover it all. We'll cover common and not-so-common challenges faced in the blockchain life cycle. Later, we'll delve into how we can interact with the Hyperledger Fabric blockchain, covering all the principles you need to master, such as chaincode, smart contracts, and much more. We'll also address the scalability and security issues currently faced in blockchain development.
By the end of this book, you will be able to implement each recipe to plan, design, and create a full-fledged, private, decentralized application to meet organizational needs.
What you will learn
- Create the most popular permissioned blockchain network with Fabric and Composer
- Build permissioned and permission-less blockchains using Sawtooth
- Utilize built-in Iroha asset/account management with role-based permissions
- Implement and run Ethereum smart contracts with Burrow
- Get to grips with security and scalability in Hyperledger
- Explore and view blockchain data using Hyperledger Explorer
- Produce reports containing performance indicators and benchmarks using Caliper
Who this book is for
This book is for blockchain developers who want to understand how they can apply Hyperledger services in their day-to-day projects. This book uses a recipe-based approach to help you use Hyperledger to build powerful, decentralized autonomous applications. We assume the reader has a basic knowledge of the Blockchain technology and cryptography concepts
Xun (Brian) Wu
Brian is a senior blockchain architect and consultant. He is a prolific writer on the subject of blockchain. As one of the prominent voices in the blockchain community, he has written 7 books on blockchain covering popular blockchain technologies like Hyperledger and Ethereum from beginner to advance levels. He has 18+ years of extensive hands-on experience with blockchain-based enterprise application design and development, big data, cloud computing, UI, and system infrastructure solutions. He has also successfully repurposed and integrated the blockchain-based applications into gaming, supply chain, digital asset tokenization platform as well as, cryptocurrency blockchain analytics industries. In addition to his strong background in the blockchain space, he has served as the tech lead for multiple key technology initiatives at leading financial institutions including J.P. Morgan, Citigroup, and Bank of America.
Read more from Xun (Brian) Wu
Security Tokens and Stablecoins Quick Start Guide: Learn how to build STO and stablecoin decentralized applications Rating: 0 out of 5 stars0 ratingsBlockchain Development with Hyperledger: Build decentralized applications with Hyperledger Fabric and Composer Rating: 0 out of 5 stars0 ratingsLearn Ethereum.: A practical guide to help developers set up and run decentralized applications with Ethereum 2.0 Rating: 0 out of 5 stars0 ratingsLearn Ethereum: Build your own decentralized applications with Ethereum and smart contracts Rating: 0 out of 5 stars0 ratingsBlockchain Quick Start Guide: A beginner's guide to developing enterprise-grade decentralized applications Rating: 0 out of 5 stars0 ratingsBlockchain By Example: A developer's guide to creating decentralized applications using Bitcoin, Ethereum, and Hyperledger Rating: 0 out of 5 stars0 ratings
Related to Hyperledger Cookbook
Related ebooks
Hands-On Blockchain with Hyperledger: Building decentralized applications with Hyperledger Fabric and Composer Rating: 0 out of 5 stars0 ratingsBlockchain for Enterprise: Build scalable blockchain applications with privacy, interoperability, and permissioned features Rating: 0 out of 5 stars0 ratingsBlockchain By Example: A developer's guide to creating decentralized applications using Bitcoin, Ethereum, and Hyperledger Rating: 0 out of 5 stars0 ratingsBlockchain Quick Reference: A guide to exploring decentralized blockchain application development Rating: 0 out of 5 stars0 ratingsBlockchain for Decision Makers: A systematic guide to using blockchain for improving your business Rating: 0 out of 5 stars0 ratingsBurp Suite Cookbook: Practical recipes to help you master web penetration testing with Burp Suite Rating: 0 out of 5 stars0 ratingsBuilding Blockchain Projects Rating: 2 out of 5 stars2/5Web Development with Angular and Bootstrap: Embrace responsive web design and build adaptive Angular web applications, 3rd Edition Rating: 0 out of 5 stars0 ratingsGo Web Scraping Quick Start Guide: Implement the power of Go to scrape and crawl data from the web Rating: 0 out of 5 stars0 ratingsLearning Bootstrap Rating: 1 out of 5 stars1/5Ethereum Smart Contract Development: Build blockchain-based decentralized applications using solidity Rating: 0 out of 5 stars0 ratingsPython for Finance Cookbook: Over 50 recipes for applying modern Python libraries to financial data analysis Rating: 0 out of 5 stars0 ratingsD3.js Quick Start Guide: Create amazing, interactive visualizations in the browser with JavaScript Rating: 0 out of 5 stars0 ratingsBlockchain for Business 2019: A user-friendly introduction to blockchain technology and its business applications Rating: 0 out of 5 stars0 ratingsBlockchain for Business with Hyperledger Fabric: A complete guide to enterprise blockchain implementation using Hyperledger Fabric Rating: 0 out of 5 stars0 ratingsHands-On Bug Hunting for Penetration Testers: A practical guide to help ethical hackers discover web application security flaws Rating: 0 out of 5 stars0 ratingsPractical C Programming: Solutions for modern C developers to create efficient and well-structured programs Rating: 0 out of 5 stars0 ratingsEmbedded Programming with Modern C++ Cookbook: Practical recipes to help you build robust and secure embedded applications on Linux Rating: 0 out of 5 stars0 ratingsHands-On Full Stack Development with Go: Build full stack web applications with Go, React, Gin, and GopherJS Rating: 0 out of 5 stars0 ratingsHands-On Machine Learning with C#: Build smart, speedy, and reliable data-intensive applications using machine learning Rating: 0 out of 5 stars0 ratingsCloud Analytics with Google Cloud Platform: An end-to-end guide to processing and analyzing big data using Google Cloud Platform Rating: 0 out of 5 stars0 ratings
Security For You
Tor and the Dark Art of Anonymity Rating: 5 out of 5 stars5/5Cybersecurity: The Beginner's Guide: A comprehensive guide to getting started in cybersecurity Rating: 5 out of 5 stars5/5How to Become Anonymous, Secure and Free Online Rating: 5 out of 5 stars5/5CompTIA Security+ Study Guide: Exam SY0-601 Rating: 5 out of 5 stars5/5Remote/WebCam Notarization : Basic Understanding Rating: 3 out of 5 stars3/5Cybersecurity For Dummies Rating: 5 out of 5 stars5/5Wireless Hacking 101 Rating: 5 out of 5 stars5/5Hacking For Dummies Rating: 4 out of 5 stars4/5The Hacker Crackdown: Law and Disorder on the Electronic Frontier Rating: 4 out of 5 stars4/5Wireless and Mobile Hacking and Sniffing Techniques Rating: 0 out of 5 stars0 ratingsSocial Engineering: The Science of Human Hacking Rating: 3 out of 5 stars3/5Make Your Smartphone 007 Smart Rating: 4 out of 5 stars4/5CompTIA Security+ Study Guide with over 500 Practice Test Questions: Exam SY0-701 Rating: 0 out of 5 stars0 ratingsCompTIA Network+ Review Guide: Exam N10-008 Rating: 0 out of 5 stars0 ratingsHacking : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Ethical Hacking Rating: 5 out of 5 stars5/5Mike Meyers' CompTIA Security+ Certification Guide, Third Edition (Exam SY0-601) Rating: 5 out of 5 stars5/5Cybersecurity All-in-One For Dummies Rating: 0 out of 5 stars0 ratingsCompTIA Network+ Practice Tests: Exam N10-008 Rating: 0 out of 5 stars0 ratingsCodes and Ciphers Rating: 5 out of 5 stars5/5How to Hack Like a Pornstar Rating: 5 out of 5 stars5/5Blockchain Basics: A Non-Technical Introduction in 25 Steps Rating: 5 out of 5 stars5/5The Cyber Attack Survival Manual: Tools for Surviving Everything from Identity Theft to the Digital Apocalypse Rating: 0 out of 5 stars0 ratingsIAPP CIPP / US Certified Information Privacy Professional Study Guide Rating: 0 out of 5 stars0 ratingsCodes and Ciphers - A History of Cryptography Rating: 4 out of 5 stars4/5The Mathematics of Secrets: Cryptography from Caesar Ciphers to Digital Encryption Rating: 5 out of 5 stars5/5CompTIA Network+ Certification Guide (Exam N10-008): Unleash your full potential as a Network Administrator (English Edition) Rating: 0 out of 5 stars0 ratings
Reviews for Hyperledger Cookbook
0 ratings0 reviews
Book preview
Hyperledger Cookbook - Xun (Brian) Wu
Hyperledger Cookbook
Over 40 recipes implementing the latest Hyperledger blockchain frameworks and tools
Xun (Brian) Wu
Chuanfeng Zhang
Andrew Zhang
BIRMINGHAM - MUMBAI
Hyperledger Cookbook
Copyright © 2019 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Sunith Shetty
Acquisition Editor: Joshua Nadar
Content Development Editor: Karan Thakkar
Technical Editor: Suwarna Patil
Copy Editor: Safis Editing
Language Support Editor: Storm Mann
Project Coordinator: Hardik Bhinde
Proofreader: Safis Editing
Indexer: Pratik Shirodkar
Graphics: Jisha Chirayil
Production Coordinator: Deepika Naik
First published: April 2019
Production reference: 1300419
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78953-488-7
www.packtpub.com
mapt.io
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
Packt.com
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.
At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Contributors
About the authors
Xun (Brian) Wu is an author, software architect, and advisor with over 17 years' extensive hands-on experience in blockchain design and development, big data, AI, the cloud, UIs, and system infrastructures. He has worked for top investment banks including J.P. Morgan, Citigroup, and Bank of America. He is a coauthor of Blockchain Quick Start Guide, Blockchain By Example, and Seven NoSQL Databases in a Week, and has worked as a technical reviewer on over 50 technical computer books for Packt. He owns several blockchain patents, and currently serves as a board advisor for several blockchain start-up companies. Brian holds an NJIT computer science master's degree. He lives in New Jersey with his two beautiful daughters, Bridget and Charlotte.
I would like to thank my parents, wife and kids for their patience and support throughout this endeavor.
Chuanfeng Zhang is enthusiastic and passionate about technologies and trading and data analysis, with 20 years' experience in both the technology and finance sectors. He has worked at top investment banks and technology firms including Goldman Sachs, Credit Suisse, and IBM. He has led, designed, and successfully developed many enterprise-scale systems with diverse architectures for algorithmic trading, order management, risk management, business intelligence, and more.
I would like to especially thank my lovely wife and kids (Kathleen and Kevin) for their support for this project.
Andrew Zhang is an IBM Watson Cloud Advocate. He has many years of experience in cloud platforms, big data analytics, and machine learning. He works with start-ups and enterprise clients in the government, education, healthcare, and life science industries. His current interests are in embedding AI and blockchain open source technologies for consumer and enterprise applications. In his spare time, Andrew enjoys reading, traveling, and spending time with his family and friends.
Contributing author
Belinda Li is a seasoned software engineer. Her recent endeavors include MLaaS, AI enabled applications, and permissioned blockchain technologies. She is entrepreneurial and has over 15 years of hands-on enterprise software design and development experience in wealth management brokerage and trading platforms, investment portfolio optimization and analytics, call center training and operations, single sign-on security, and more. Belinda has held various positions in top-tier financial firms including Morgan Stanley and Citigroup. She started her career as a C/C++ programmer in the math department in Intergraph Corporation, a pioneer in GIS and the global leader in CAD software. She enjoys Zumba, folk dancing, and traveling in her free time.
About the reviewer
Rameshwar Nigam is the director and founder of Pytriot Solutions LLP. He oversees the design and deployment of blockchain services. With strategic thinking, sharp analytical skills, and business acumen, Rameshwar can identify business opportunities and develop solutions for managing business challenges. His in-depth knowledge of blockchain and associated domains aids organizations in the seamless and risk-free adoption of these technologies. He continues to build awareness and recognition of blockchain as a technology in various corporates by providing training, proofs-of-concept, and so on.
Packt is searching for authors like you
If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.
Table of Contents
Title Page
Copyright and Credits
Hyperledger Cookbook
About Packt
Why subscribe?
Packt.com
Contributors
About the authors
Contributing author
About the reviewer
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Conventions used
Sections
Getting ready
How to do it…
How it works…
There's more…
See also
Get in touch
Reviews
Working with Hyperledger Fabric
Reviewing the Hyperledger Fabric architecture and components
Getting ready
How to do it...
How it works...
Installing Hyperledger Fabric on AWS
Getting ready
How to do it...
How it works...
Building the Fabric network
How to do it...
How it works...
Adding an organization to a channel
Getting ready...
How to do it...
How it works...
There's more...
Using CouchDB
How to do it...
How it works...
Writing your first application
How to do it...
Accessing the API with SDK
How it works...
See also
Implementing Hyperledger Fabric
Inventory asset management
Writing chaincode as a smart contract
Getting ready
Writing chaincode using Go
How to do it...
The OrgAsset entity
The Init function
The Invoke function
The query and getHistory functions
How it works...
The Init function
The Invoke function
The query function
Compiling and deploying Fabric chaincode
Getting ready
How to do it...
Starting the sample Fabric network
Building and deploying the chaincode
How it works...
Running and testing the smart contract
How to do it...
Installing the assermgr chaincode
Instantiating the assermgr chaincode
Invoking the assermgr chaincode
How it works...
Developing an application with Hyperledger Fabric through the SDK
How to do it...
Creating and executing startFabric.sh
Setting up a client project
Writing Node.js sever-side code
Writing Node.js client-side code
Running the web application
How it works...
Modeling a Business Network Using Hyperledger Composer
The Hyperledger Composer business network and development components
Getting ready
How to do it...
Process flow
Entities
Assets
Query
How it works...
Setting up the Hyperledger Composer prerequisites environment
Getting ready
How to do it...
How it works...
Setting up the development environment
Getting ready
How to do it...
How it works...
Configuring a Composer business network
How to do it...
How it works...
Implementing models, transaction logic, access control, and query definitions
Getting ready
How to do it...
How it works...
There's more...
Deploying, testing, and exporting business network archives using the Composer command-line interface
Getting ready
How to do it...
How it works...
Interacting with Composer through the RESTful API
Getting ready
How to do it...
How it works...
Integrating Hyperledger Fabric with Explorer
Technical requirements
Setting up the Hyperledger Explorer environment
Getting ready
How to do it...
Installing Hyperledger Explorer and setting up the database
How to do it...
Configuring Hyperledger Explorer with Fabric
Getting ready
How to do it...
How it works...
Building Hyperledger Explorer
How to do it...
Running the Hyperledger Explorer application
Getting ready
How to do it...
Working with Hyperledger Sawtooth
Introduction
Installing Hyperledger Sawtooth
Getting ready
How to do it...
Configuring Hyperledger Sawtooth
How to do it...
How it works...
Designing a namespace and address
Getting ready
How to do it...
How it works...
The namespace and address scheme
There's more...
Implementing a transaction family
How to do it...
How it works...
Building a transaction processor
Getting ready
How to do it...
Registering the transaction handler to the transaction processor
Implementing the transaction handler class
Building the command-line script
Setting up the transaction processor as a service
Building a Python egg and installing your python package
Starting the transaction processor service
How it works...
Granting permissions on the Sawtooth network
How to do it...
How it works...
There's more...
Developing client applications with the Sawtooth REST API and SDK
How to do it...
Step 1 – Generating a private/public key-pair and creating a signer instance
Step 2 – Implementing transaction-payload encoding
Step 3 – Implementing the namespace prefix and address scheme
Step 4 – Building a transaction header and a transaction
Step 5 – Building a batch
Step 6 – Submitting the batch with REST API
Step 7 – Building the client application
Step 8 – Testing the sample client
How it works...
Operating an Ethereum Smart Contract with Hyperledger Burrow
Introduction
An introduction to Seth
Installing Hyperledger Burrow on AWS
Getting ready
How to do it...
How it works...
Writing smart contracts with Solidity
Getting ready
How to do it...
How it works...
Using the pragma version and importing another source file
Using contracts
Deploying and calling the Ethereum smart contract on Burrow
Getting ready
How to do it...
How it works...
Installing Hyperledger Seth with Docker on AWS
How to do it...
How it works...
Creating externally owned accounts and writing Solidity contracts on Seth
How to do it...
How it works...
Deploying and calling Ethereum contracts with the Seth CLI and RPC
How to do it...
How it works...
Permissioning Ethereum EOA and contract accounts on Seth
How to do it...
How it works...
Working with Hyperledger Iroha
Installing Hyperledger Iroha on AWS
How to do it...
How it works...
Configuring Hyperledger Iroha
Getting ready
How to do it...
How it works...
Interacting with Hyperledger Iroha using the CLI to create cryptocurrency
Getting ready
How to do it...
How it works...
There's more...
Interacting with Hyperledger Iroha using the client library
Getting ready
How to do it...
How it works...
Exploring the CLI with Hyperledger Indy
Introduction
Installing Hyperledger Indy and the Indy CLI on AWS
Getting ready
How to do it...
How it works...
There's more...
Exploring the Indy CLI with Hyperledger Indy
Getting ready
How to do it...
Running the Indy CLI
Creating, opening, and listing the wallet
Creating, importing, and using the DID
Creating, connecting, and listing the Indy node pool
Sending NYM transactions to the ledger
Posting the credential schema and credential definition transaction to the ledger
How it works...
Hyperledger Blockchain Scalability and Security
Hyperledger blockchain scalability and performance
How to do it...
Block-size scaling
Endorser scaling
The endorser policy
Channels and resource allocation
Hyperledger blockchain security
How to do it...
The Fabric CA server
The Fabric CA client
The Fabric CA database
How it works...
Hyperledger performance measurement
Getting ready
How to do it...
Installing dependencies
Running the benchmark
How it works...
The adaption layer
The interface and core layer
The application layer
See also
Hyperledger Blockchain Ecosystem
An introduction to the Hyperledger family
The framework projects
The tool projects
Building the Hyperledger framework layers
The Hyperledger design philosophy at a glance
Framework architecture overview
The consensus layer
Smart contracts
Solving business problems with Hyperledger
IBM and Walmart – blockchain for food safety with Hyperledger Fabric
The problem
The approach
The results
ScanTrust and Cambio Coffee – supply-chain blockchain with Hyperledger Sawtooth
The problem
The approach
The results
BC and VON – cutting government red tape with Hyperledger Indy
The problem
The approach
The results
Other Books You May Enjoy
Leave a review - let other readers know what you think
Preface
Hyperledger is an umbrella project of modular open source frameworks and tools for building and experimenting with blockchains. The Hyperledger Cookbook provides hands-on experiences and in-depth illustrations covering the full spectrum of Hyperledger offerings. You will not only learn a range of permissioned business blockchain technologies, including Fabric, Sawtooth, Burrow, Iroha, and Indy, but also a set of tools to work with these blockchain frameworks, including Composer, Explorer, and Caliper.
Each chapter contains a set of recipes that helps the reader to become more familiar with Hyperledger blockchain and its tools. The examples in this book will help readers to apply Hyperledger technologies to their own problems.
Who this book is for
This book is for blockchain developers who want to learn about the permissioned blockchain technologies for business offered by Hyperledger. With an abundance of recipes covering distributed ledger networks, smart contract engines, client libraries, and various tools in Hyperledger technologies, blockchain developers can apply them to rapidly develop decentralized DLT systems for their enterprises. For more experienced blockchain developers, the recipes covered in this book might expose them to new ways of thinking in terms of how to select and build enterprise blockchain for their business use cases.
What this book covers
Chapter 1, Working with Hyperledger Fabric, concentrates on the fundamental Fabric architecture and components. The recipes cover installation, building a Fabric network, adding an org to a channel, integrating with CouchDB, and writing your first Fabric application.
Chapter 2, Implementing Hyperledger Fabric, is dedicated to building a simple device asset management DApp. The example covers recipes designed to show how to design and write a chaincode smart contract, compile and deploy Fabric chaincode, run and test the smart contract, develop a DApp, and interact with Hyperledger Fabric chaincode through the client SDK API.
Chapter 3, Modeling a Business Network Using Hyperledger Composer, contains recipes designed to show how to use the Composer tool to rapidly develop use cases, build blockchain business networks using the Composer model language, deploy, test and export BNA using the Composer CLI tool, and interact with Composer through the SDK.
Chapter 4, Integrating Hyperledger Fabric with Explorer, this includes installing, setting up, and configuring Hyperledger Explorer, integrating with the Hyperledger framework, and running the Hyperledger Explorer application.
Chapter 5, Working with Hyperledger Sawtooth, includes recipes for installing, deploying, and running DApps with Hyperledger Sawtooth. With the help of Hyperledger Sawtooth's modular architecture, distributed ledger, distributed data storage, and decentralized consensus, several examples demonstrate how to build a transaction processor, design a namespace and address, grant permission on the Sawtooth network, and develop client applications with the Sawtooth RestAPI and SDK.
Chapter 6, Operating an Ethereum Smart Contract with Hyperledger Burrow, contains recipes about how to write smart contracts with Solidity, deploy and interact with Ethereum smart contracts on Burrow, invoke smart contracts with Seth CLI and RPC, and create externally owned accounts on Seth. This chapter also covers the permissioning of Ethereum EOA and contract accounts on Seth.
Chapter 7, Working with Hyperledger Iroha, covers several recipes associated with working with Hyperledger Iroha, including installing and configuring Hyperledger Iroha, and interacting with Hyperledger Iroha using the client library. This chapter also provides an example demonstrating how to use Iroha CLI to create a cryptocurrency.
Chapter 8, Exploring the CLI with Hyperledger Indy, covers the installation of Hyperledger Indy and the exploration of Indy CLI with Hyperledger Indy.
Chapter 9, Hyperledger Blockchain Scalability and Security, contains recipes about how to measure Hyperledger blockchain performance using the Hyperledger Caliper tool, how to design and implement