Reader small image

You're reading from  Blockchain with Hyperledger Fabric - Second Edition

Product typeBook
Published inNov 2020
PublisherPackt
ISBN-139781839218750
Edition2nd Edition
Concepts
Right arrow
Authors (6):
Nitin Gaur
Nitin Gaur
author image
Nitin Gaur

Nitin Gaur, is the director of IBM's Blockchain Labs, and an IBM Distinguished Engineer.
Read more about Nitin Gaur

Anthony O'Dowd
Anthony O'Dowd
author image
Anthony O'Dowd

Anthony O'Dowd is a Distinguished Engineer at IBM, focusing on Blockchain. He led IBM's contribution to the design and development of the new smart contract and application SDKs found in Hyperledger Fabric v2. Anthony has also made significant contributions to Hyperledger Fabric documentation and samples.
Read more about Anthony O'Dowd

Petr Novotny
Petr Novotny
author image
Petr Novotny

Petr Novotny is a research scientist at IBM Research, with an MSc from University College London and PhD from Imperial College London, where he was also a post-doctoral research associate.
Read more about Petr Novotny

Luc Desrosiers
Luc Desrosiers
author image
Luc Desrosiers

Luc Desrosiers is an IBM-certified IT architect with 20+ years of experience.
Read more about Luc Desrosiers

Venkatraman Ramakrishna
Venkatraman Ramakrishna
author image
Venkatraman Ramakrishna

Venkatraman Ramakrishna is an IBM researcher, with a BTech from IIT Kharagpur and PhD from UCLA.
Read more about Venkatraman Ramakrishna

Salman A. Baset
Salman A. Baset
author image
Salman A. Baset

Dr. Salman A. Baset is the CTO of security in IBM Blockchain Solutions.
Read more about Salman A. Baset

View More author details
Right arrow

Setting the Stage with a Business Scenario

The first three chapters were focused on setting the stage, defining the landscape of a blockchain project, and introducing the concept of business networks. We now understand how the technology works within a business framework, how the various Hyperledger projects aim to solve the problem of time and trust, why different stakeholders would come together to create a business network, and what a business network comprises.

With an understanding of the components that make up Hyperledger Fabric and a generic business network, we will now delve into application design and implementation considerations. The next few chapters will take you through the steps of creating a sample network, building your very own smart contract, and then integrating it into applications.

In order to make these exercises relevant, we will leverage a business use case with roots in older civilizations: trading and letters of credit.

The chapter...

Trading and letters of credit

Step back in history to a time when merchants traveled across continents to buy cloth in one country to sell in another country. As a Florentine wool merchant, you might make a journey to Amsterdam to buy fine wool in that newly formed city-state, whose port collected resources from the whole of Northern Europe and beyond. You could then transport the wool to Florence, where it could be sold to tailors making fine garments for their wealthy clients. We're talking about 1300 AD—a time when it was not safe to carry gold or other precious metals as a form of currency to buy and sell goods. What was necessary was a form of currency that worked across country boundaries, one that could be used in Amsterdam and Florence, or anywhere!

Marco Polo had been to China and had seen how commerce was conducted in that thriving economy. At the heart of the successful Khan empire were advanced financial techniques that we would recognize today. Fiat currencies...

Business scenario and use case

The letter of credit is but one facet of a complex process that parties engaging in international trade must go through. The export of goods across international boundaries involves many entities playing different roles and possessing different, sometimes mutually contradictory, interests. Traditionally, this process has relied on a lot of documentation that has to be physically transferred between entities. This can be quite inefficient, time-consuming, costly, and prone to manipulation by vested interests. But these are exactly the kinds of real-world problems that blockchains were designed to mitigate. Therefore, we have selected an element of an import-export scenario with simplified versions of transactions carried out in the real world as our canonical use case for practical exercises in the next few chapters.

Overview

The scenario we will describe involves a simple transaction: the sale of goods from one party to another. This...

Designing and configuring a Hyperledger Fabric trade network

As you already know by now, an instance of a Hyperledger Fabric blockchain is referred to as a channel, which is a log of transactions linked to each other sequentially in a cryptographically secure manner. To design and run a blockchain application, the first step is to determine how many channels are required. For our trade application, we will use two channels, which will maintain the history of trades carried out among the different participants along with associated artifacts like letters of credit, export licenses, bills of lading, bank accounts, and shipment records.

A Fabric peer may belong to multiple channels, which maintain independent and isolated sequences of transactions and resulting datasets. A single peer may thus access ledger data from, and run transactions in, different applications (or contracts) on behalf of its owners (or clients). A channel can run multiple smart contracts, each of which...

Launching a sample trade network

To launch the sample trade network, all we need to do is start the network using the docker-compose command, as follows:

$ docker-compose -f docker-compose-e2e.yaml -f docker-compose-couchdb.yaml up

You can run this as a background process and redirect the standard output to a log file if you so choose. Otherwise, you will see the various containers starting up and logs from all of them displayed on the console.

To run the basic network using the preceding command and to develop applications in later chapters, ensuring cross-connectivity between services running in various containers is crucial. For this, you may need to map the various container names to the localhost IP address in your host machine's HOSTS file. For example, on a Linux machine, you can add the following entries to /etc/hosts:

127.0.0.1       orderer.trade.com
127.0.0.1       peer0.exporterorg.trade.com
127.0.0.1       peer0.importerorg.trade.com
127...

Configuring our development environment for network operations

Our final task in this chapter is to get our application development environment, namely VS Code using the IBP extension, connected to the network we just launched. This is a two-step process:

  1. First, we will create and load identity wallets for all our network participants in VS Code.
  2. Next, we will create an environment for trade network operations and connect to the running network using identities from these wallets.

Creating Fabric identity wallets

If you do not have VS Code already running, restart it. On an Ubuntu Linux machine, this can be done by running the code command. Navigate to the IBP extension by selecting the appropriate tab from the left-hand menu. Now focus on the FABRIC WALLETS panel at the bottom left of the main view, which may contain wallets for the organizations of the 1 Org Local Fabric environment we tested earlier, or be empty as follows (if you tore down the environment...

Summary

In this chapter, we introduced the business use case that the following chapters will leverage to create a context around the code we will write. We have also deployed our first Hyperledger Fabric network and have now transitioned from theory to practice. Well done!

The next few chapters will take you through the development of a blockchain application from the bottom up: (1) smart contracts using Java, Node.js, and developer tools, and (2) higher-layer business applications using the Fabric Gateway SDK and VS Code.

Through this exercise, we hope to give you an understanding of the flexibility of the solution and the ability to leverage each tool in the right context. To get ready for the next chapter, you should now stop your network using ./trade.sh down.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Blockchain with Hyperledger Fabric - Second Edition
Published in: Nov 2020Publisher: PacktISBN-13: 9781839218750
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 (6)

author image
Nitin Gaur

Nitin Gaur, is the director of IBM's Blockchain Labs, and an IBM Distinguished Engineer.
Read more about Nitin Gaur

author image
Anthony O'Dowd

Anthony O'Dowd is a Distinguished Engineer at IBM, focusing on Blockchain. He led IBM's contribution to the design and development of the new smart contract and application SDKs found in Hyperledger Fabric v2. Anthony has also made significant contributions to Hyperledger Fabric documentation and samples.
Read more about Anthony O'Dowd

author image
Petr Novotny

Petr Novotny is a research scientist at IBM Research, with an MSc from University College London and PhD from Imperial College London, where he was also a post-doctoral research associate.
Read more about Petr Novotny

author image
Luc Desrosiers

Luc Desrosiers is an IBM-certified IT architect with 20+ years of experience.
Read more about Luc Desrosiers

author image
Venkatraman Ramakrishna

Venkatraman Ramakrishna is an IBM researcher, with a BTech from IIT Kharagpur and PhD from UCLA.
Read more about Venkatraman Ramakrishna

author image
Salman A. Baset

Dr. Salman A. Baset is the CTO of security in IBM Blockchain Solutions.
Read more about Salman A. Baset