Creating a Hyperledger Fabric network from scratch — Part I Designing the network

0
43

Creating a Hyperledger Fabric network from scratch — Part I Designing the network

Introduction

This will be the first of a series of tutorials that show how to create a Hyperledger Fabric network from scratch, with several actors and getting to create a Rest API to interact with it.

Requirements

To be able to start with this tutorial, it is necessary to have the dependencies mentioned in this post installed:

How to install a Hyperledger Fabric network in localhost

Definition of the use case

Hyperledger Fabric is starting to be used to create networks that serve as traceability control in a supply chain, so we will study a case like this. To base on an example we will take the traceability of the tuna from which some project has been made, between companies and we will trace the origin from the product, from the producer, through a factory where it is transform into sushi and reaches the points of sale.

In order to do a standard network that can be used in case of similar uses, we will create the organizations:

  • Producer: raw material producer
  • Deliverer: Delivery between the different points of sale
  • Manufacturer: Manufacturer that transforms the raw material into another product
  • Retailer: Point of sale where the final product is sold.

These organizations will be responsible for storing in the blockchain the states through which the product passes, from its capture, keeping its location, to its transport or handling, indicating that raw material is involved in each product.

Creating the project

Once we have installed the necessary Hyperledger dependencies, we will create our project. To speed up this task, I have created a template with a base project of two organizations, which we will use as a guide.

To begin, we must place ourselves in the directory of examples of fabric, with:

cd fabric-samples

In this directory we can clone the template, assigning a name that is identifying

git clone https://github.com/ialberquilla/hlf1.4-template.git supply-network

In this way we will have the repository in our local machine.

Defining the organizations

In order to define the scheme we created earlier, we have to modify three important files crypto-config.yaml configtx.yaml and docker-compose-cli.yaml

  • crypto-config.yaml: In this file we will define the organizations that will be part of the network, and the orderer node that will be in charge of ordering the transactions to include them in the ledger:
  • configtx.yaml: In this file we should include an entry for each of the organizations with its MSP (Membership Service Providers) indicator to identify it as part of the network, and be able to belong to the channel, consulting and sending transactions. In addition to this we will insert the names of the organizations in the consortium, and in the channel so that they can be part of it.

docker-compose-cli.yaml: This file is responsible for booting the entire network, in it we will define the docker containers that will be started to define the organizations and we will also include a CA for each organization to manage the certificates of the users that will interact with them. Another important container that we define here is the CLI, it is a container that will provide us with a command line, to be able to create the channels, join to install chaincodes….

Once we have defined this, we see that our docker-compose-cli.yaml refers to another base / docker-compose-base.yaml file. This contains all the properties of the containers, name, port on which they boot and volumes they use, also refer to the type of service they will start from peer-base. This file in the repository is defined as docker-compose-base-template.yaml, since it includes variables that have to be replaced once the certificates are generated, in this way, we create the template and we will make a script that automatically replace these variables once the certificates have been generated, and generate another file without the template suffix.

With this, we would have defined our organizations, in the next post, we will create the scripts to be able to start the network and join the organizations to a channel.

Part II can be found here

Creating a Hyperledger Fabric network from scratch — Part II Starting the network


Creating a Hyperledger Fabric network from scratch — Part I Designing the network was originally published in Coinmonks on Medium, where people are continuing the conversation by highlighting and responding to this story.