Reader small image

You're reading from  Blockchain Quick Start Guide

Product typeBook
Published inDec 2018
Reading LevelIntermediate
PublisherPackt
ISBN-139781789807974
Edition1st Edition
Languages
Concepts
Right arrow
Authors (2):
Xun (Brian) Wu
Xun (Brian) Wu
author image
Xun (Brian) Wu

Xun (Brian) Wu is a senior blockchain architect and consultant. With over 20 years of hands-on experience across various technologies, including Blockchain, big data, cloud, AI, systems, and infrastructure, Brian has worked on more than 50 projects in his career. He has authored nine books, which have been published by O'Reilly, Packt, and Apress, focusing on popular fields within the Blockchain industry. The titles of his books include: Learn Ethereum (First Edition), Learn Ethereum (Second Edition), Blockchain for Teens, Hands-On Smart Contract Development with Hyperledger Fabric V2, Hyperledger Cookbook, Blockchain Quick Start Guide, Security Tokens and Stablecoins Quick Start Guide, Blockchain by Example, and Seven NoSQL Databases in a Week.
Read more about Xun (Brian) Wu

Weimin Sun
Weimin Sun
author image
Weimin Sun

Weimin Sun has 20 years' of experience working in the financial industry. He has worked for top-tier investment and commercial banks such as J.P. Morgan, Bank of America, Citibank, and Morgan Stanley, where he also managed large teams for developing IT applications. Weimin has also held corporate titles such as executive director and senior VP in some of these firms. Weimin has in-depth knowledge of the blockchain technology, data science, data architecture, data modeling, and big data platforms. He holds Ph.D, M.B.A and M.Sc degrees. He has co-authored Blockchain Quick Start Guide and published several statistical journal papers.
Read more about Weimin Sun

View More author details
Right arrow

Chapter 5. Exploring an Enterprise Blockchain Application Using Hyperledger Fabric

 the previous chapter, we discussed the Ethereum blockchain. Ethereum is a public blockchain; anyone can read the blockchain data and make legitimate changes. Anyone can write a new block into the chain. Ethereum is fully autonomous and is not controlled by anyone. The smart contract is written in Solidity, as a nearly Turing complete language, that can run on the Ethereum virtual machine (EVM) to execute various transactions. Developers can build and deploy decentralized applications (DApps) using these smart contracts. Ether is a cryptocurrency in Ethereum, and acts as fuel for every operation in Ethereum, including executing smart contracts, DApps, transactions, and so on. However, this is not the only way to build a blockchain.

Blockchains that require an access control layer built into the blockchain nodes to read restricted information on the blockchain can be created. This will limit the number of participants...

Key concepts in Hyperledger Fabric


If you want to use Hyperledger Fabric effectively, you have to understand its key concepts. This includes ledger, chaincode, and channel.

Ledger

The ledger is the sequenced, immutable, entire historical record of all state transactions. All the transactions that are performed will be added to the ledger. We can find the entire transaction history for each channel. A fabric blockchain ledger has two types of data—a world state and a blockchain transaction ledger. The world state, which is stored stored in a database, LevelDB, is the default database. The state data is mutable. It has a version number that keeps incrementally updated when the state changes. On the other hand, the ledger data is immutable, and is stored as a file. It records transaction data block information, which contains a sequence of transactions. Each block's header includes a hash of the block's transactions, as shown in the following diagram:

Chaincode

Chaincode is a program (or programs...

Core component model


To run Hyperledger Fabric, we need a few main components; these are a Membership Service Provider (MSP), Fabric CA, peers, and an ordering service. We need to understandexactly how they work and the way to collect them.

Peers

The peers are the physical layer where the ledger data is stored and the chaincode is processed. A blockchain network is comprised primarily of a set of peer nodes. Every peer maintains its own copy of the shared ledger and is certified by a single MSP. The peer can have two roles: endorsing nodes or committing nodes.

The endorsing node processes transaction proposals and it returns the signed result to the client.

The ordering service sends a block of transactions to the committing node. The committing node validates if the data is in a consistent state. Once verified, it commits the transaction in the ledger and updates the world state in store data.

Membership service provider (MSP)

MSP is a pluggable interface that aims to offer an abstraction of...

Setting up a Hyperledger Fabric environment


So far, we have learned about the key concepts of Hyperledger Fabric. In this section, we will set up a Hyperledger Fabric development environment. Before continuing with the installation steps, let's take a look at the prerequisites for fabric installation.

 

 

 

 

 

 

Installation prerequisites

The following are the prerequisites for installing the required development tools.

Ubuntu Linux 14.04 / 16.04 LTS (both 64-bit), or macOS 10.12

Docker Engine: Version 17.03 or higher

Docker-Compose: Version 1.8 or higher

 

Node: 8.9 or higher (note version 9 is not supported)

npm: v5.x

git: 2.9.x or higher

Python: 2.7.x

 

 

We will use Ubuntu for our development environment. We can download the prerequisites using the following commands:

curl -O https://hyperledger.github.io/composer/latest/prereqs-ubuntu.sh
chmod u+x prereqs-ubuntu.sh
./prereqs-ubuntu.sh

It may prompt for your password, since it uses sudo during its execution.

Installing Hyperledger Fabric

Create and navigate...

Writing chaincode


Chaincode is similar to a smart contract. It defines and executes the business logic invoked by authorized participants in a specific network. A chaincode is written in Go or Node.js. In our example, we will use Go.

There are many IDEs and tools to support Golang. Here are some popular IDEs that work great with Golang.

Development tools

There are various tools that support Go development. Some popular IDEs are listed in the following sections.

LiteIDE 

LiteIDE is an open source Go IDE that was directly designed for Golang. There are a bunch of useful features available for Go developers, including a configurable code editor, customized build commands, many building options, and Golang support.

JetBrains Gogland

Gogland has a powerful built-in autocomplete engine, errors detection, code refactoring tools, and more.

Visual Studio Code

You can install Go extension in Visual Studio Code. It provides code hints and the ability to debug code.

In this chapter, we will use LiteIDE to develop...

Configuring Hyperledger Fabric


There are three entities in the insurance claim network—insuree, broker, and insurer. All of these participants will register in Fabric as a peer node. The following table describes the three peer roles and MSP information:

User ID

Role

Organization MSP ID

user_001

INSUREE

Org1MSP

broker_001

BROKER

Org2MSP

insurer_001

INSURER

Org3MSP

 

We have one insuree who joins the organization with MSP ID org1, one broker who joins the organization with MSP ID org2, and one insurer who joins the organization with MSP ID org3. For bootstrapping the fabric network, we need to first generate crypto material for all three components that we need to run.

Generating the certificate

We need to define crypto-config.yaml and use the cryptogen tool to generate the certificates for each peer. Cryptogen is available in the tools image. crypto-config.yaml contains the following information:

  • OrdererOrgs: Definition of organizations managing orderer nodes
  • PeerOrgs: Definition of organizations managing...

Summary


In this chapter, we have learned about the basics of Hyperledger Fabric's. After setting up a development environment, we wrote a chaincode for an insurance claim use case. We then studied fabric composer configuration. Finally, we ran the end-to-end fabric test execution for our insurance claim application. We can see that it is quite complex to use Hyperledger Fabric to implement aninsurance claim application. In the next chapter, we will learn how to use Hyperledger Composer to quickly write an insurance claim application.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Blockchain Quick Start Guide
Published in: Dec 2018Publisher: PacktISBN-13: 9781789807974
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Xun (Brian) Wu

Xun (Brian) Wu is a senior blockchain architect and consultant. With over 20 years of hands-on experience across various technologies, including Blockchain, big data, cloud, AI, systems, and infrastructure, Brian has worked on more than 50 projects in his career. He has authored nine books, which have been published by O'Reilly, Packt, and Apress, focusing on popular fields within the Blockchain industry. The titles of his books include: Learn Ethereum (First Edition), Learn Ethereum (Second Edition), Blockchain for Teens, Hands-On Smart Contract Development with Hyperledger Fabric V2, Hyperledger Cookbook, Blockchain Quick Start Guide, Security Tokens and Stablecoins Quick Start Guide, Blockchain by Example, and Seven NoSQL Databases in a Week.
Read more about Xun (Brian) Wu

author image
Weimin Sun

Weimin Sun has 20 years' of experience working in the financial industry. He has worked for top-tier investment and commercial banks such as J.P. Morgan, Bank of America, Citibank, and Morgan Stanley, where he also managed large teams for developing IT applications. Weimin has also held corporate titles such as executive director and senior VP in some of these firms. Weimin has in-depth knowledge of the blockchain technology, data science, data architecture, data modeling, and big data platforms. He holds Ph.D, M.B.A and M.Sc degrees. He has co-authored Blockchain Quick Start Guide and published several statistical journal papers.
Read more about Weimin Sun