A Multi Organization Application in Hyperledger Fabric

Deeptiman Pattnaik
5 min readDec 18, 2019

In this article, I will demonstrate a Multi Organization application that I have developed using Hyperledger Fabric Go SDK. I will provide the complete step by step installation and building process in this article.

Introduction

MultiOrgLedger is a web application written in Go to demonstrate the Multi Organization setup in a Hyperledger Fabric network. The blockchain network consists of four organizations joined with a single channel. The ledger data created in an organization can be accessible by the other participating organization in the network.

Github : https://github.com/Deeptiman/multiorgledger

First, we need to follow a series of installations in the local PC environment to get the project running.

Installation

MultiOrgLedger requires Go and Docker to be running the system.

  1. Docker
$ sudo apt install docker.io
$ sudo apt install docker-compose

2. Go

$ sudo apt-get update
$ sudo apt-get install golang-go

or else you can directly download the golang distribution package from the below link

Linux: https://dl.google.com/go/go1.13.5.linux-amd64.tar.gz

Windows: https://dl.google.com/go/go1.13.5.windows-amd64.msi

MacOS: https://dl.google.com/go/go1.13.5.darwin-amd64.pkg

I am working on the Linux machine for this POC, so we will be installing Linux Go binary in the local environment.

Add these following variables into the profile

$ export GOPATH=$HOME/go
$ export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
$ source ~/.profile
$ go version
$ go version go1.11 linux/amd64

Setup the Host

In the case of a multi-organization network running in the local environment, it’s required to map all the organization’s peer domain with the localhost of the system. So, we need add the followings in /etc/hosts.

127.0.0.1 orderer.multi.org.ledger.com
127.0.0.1 ca.org1.multi.org.ledger.com
127.0.0.1 peer0.org1.multi.org.ledger.com
127.0.0.1 peer1.org1.multi.org.ledger.com
127.0.0.1 peer0.org2.multi.org.ledger.com
127.0.0.1 peer1.org2.multi.org.ledger.com
127.0.0.1 peer0.org3.multi.org.ledger.com
127.0.0.1 peer1.org3.multi.org.ledger.com
127.0.0.1 peer0.org4.multi.org.ledger.com
127.0.0.1 peer1.org4.multi.org.ledger.com

Setup the Blockchain network

MultiOrgLedger is a four organization based Hyperledger application and each organization supports two peer nodes. There are few prerequisites to follow to set up and install a blockchain network in the docker container.

Prerequisites

Few binaries need to be download to create the network.

Command Reference Guide : https://hyperledger-fabric.readthedocs.io/en/release-1.4/command_ref.html

You can choose any of the following links based on your operating system and hardware architecture of your system.

[ Linux AMD 64, Linux s390x, Linux PPC64le, Windows AMD 64, Darwin AMD 64]

Configuration

Hyperledger Fabric requires few artifacts to be run as a configuration element for an organization in the network. So, We need to write certain config yaml and these will be used to generate the artifacts.

crypto-config.yaml: This configuration file will generate a few certificates and keys for the organization. The Cryptogen binary will take the config file as input and will create a crypto-config folder in the config directory, which will contain all the generated certificates and keys.

./bin/cryptogen generate --config=./crypto-config.yaml

configtx.yaml: This config file will contain configuration element details of a channel and will also create organization anchor artifacts for all four organizations.

orderer.genesis.block: This will initialize the network’s orderer.

./bin/configtxgen -profile FourOrgsOrdererGenesis -outputBlock ./artifacts/orderer.genesis.block

multiorgledger.channel.tx: This is the channel between peers to communicate in a network.

./bin/configtxgen -profile FourOrgsChannel -outputCreateChannelTx ./artifacts/multiorgledger.channel.tx -channelID multiorgledger

These are the anchor artifacts for each four organization. These artifacts will be used to communicate among organizations in the blockchain network.

#Org1
./bin/configtxgen -profile FourOrgsChannel -outputAnchorPeersUpdate ./artifacts/Org1MSPanchors.tx -channelID multiorgledger -asOrg Org1MSP
#Org2
./bin/configtxgen -profile FourOrgsChannel -outputAnchorPeersUpdate ./artifacts/Org2MSPanchors.tx -channelID multiorgledger -asOrg Org2MSP
#Org3
./bin/configtxgen -profile FourOrgsChannel -outputAnchorPeersUpdate ./artifacts/Org3MSPanchors.tx -channelID multiorgledger -asOrg Org3MSP
#Org4
./bin/configtxgen -profile FourOrgsChannel -outputAnchorPeersUpdate ./artifacts/Org4MSPanchors.tx -channelID multiorgledger -asOrg Org4MSP

Docker Compose

Now, we need to download certain images from the Docker cloud such as hyperledger/fabric-ca, hyperledger/fabric-peer, hyperledger/fabric-orderer, hyperledger/fabric-couchdb. All these images will store in the local docker container. So, we need to write a docker-compose.yaml file, where all these required images will be defined.

docker-compose.yaml:

docker-compose up -d // the docker-compose.yaml has to be located at same command location

Update the Certificate Keys

You can find newly generated certificate keys at crypto-config/ORG_DOMAIN/ca/_sk file. Add these key names in the following variables at each docker-compose-org[1,2,3,4].yaml.

[FABRIC_CA_SERVER_CA_KEYFILE , FABRIC_CA_SERVER_TLS_KEYFILE] and fabric-ca-server command parameter.

Deploy the network

There is a sequence of steps to follow to completely set up the multi-organization in the blockchain network.

Initialize SDKs for each Organization

Every organization will have its Org SDK and will be initialized with config.yaml. The initialization process will create CA clients, MSP clients, Resource Management clients, signing identity.

Create Channel

The channel will create by Orderer and will use all the signing identities of the organization admins.

Create Anchor Peers

Each organization admins will create anchor peers for their organization using the anchor peer artifacts.

Join Channel

  • After creating the channel, each anchor peer will join the channel and remember Orderer will only create the channel and he can’t join the channel.
  • s.Resmgmtis the resource management client created during Org SDK initialization. So, each organization resource management client will execute the join channel action individually.

Install Chaincode

  • Installing chaincode for the organization will use the same chaincode id & version unless it requires to be different for an organization on specific circumstances.
  • InstallCCRequest will be the same for all organizations but the request will be used by the individual resource management client of the organizations. So, the chaincode will be installed under all the organization independently.

Instantiate Chaincode

  • Chaincode instantiation under a multi org environment will be performed only once. It will be initiated by one organization’s peers and will specify certain endorsement policy considering all the organization network configurations.
  • In this POC, the chaincode policy as mentioned below
policy “OR(‘Org1MSP.member’,’Org2MSP.member’,’Org3MSP.member’,’Org4MSP.member’)”

the policy specifies that any member of any one of the organizations needs to sign a transaction before committing a block to the blockchain so another member of the organization will get a copy of the ledger data.

Affiliate an Organization

  • In Hyperledger Fabric by default “org1 & org2” are affiliated as Certificate Authority organizations.
  • But in the case of other organizations like “org3 & org4", they need to be affiliated using following CA Client API.

So, these are the essential steps for deploying multi-organization in the Hyperledger Fabric Blockchain network.

Dependency Issue

  1. Hyperledger Fabric-Go-SDK is still in development. If you do dep ensure for each Gopkg.toml in MultiOrgLedger and Chaincode, it will download the govendor folder for each module but it will have some compilation issues while building the project. So I have corrected the errors for both MultiOrgLedger and Chaincode folder.
  2. Please download the vendor folder and add it in your project directory.

Blockchain : https://www.dropbox.com/s/ry1jmw0y9xliose/vendor.zip?dl=0

Chaincode : https://www.dropbox.com/s/31nnqflpqwaywoa/vendor.zip?dl=0

Add vendor folders at the location where Gopkg.toml file is located

Run the application

  1. Compile the application and generate the multiorgledger binary for the application.
  2. Run the multiorgledger binary in the command line, you can see the server is running at PORT 6000.
  3. Now, open your browser and type http://localhost:6000
Users list reading from Hyperledger per Orgnization

So, this is the complete step by step tutorial to run the multi-organization application in a local environment using Hyperledger Fabric Go SDK.

I hope you find this article useful :)

Thanks

--

--

Working on various software development projects, [Go, Blockchain, Node.js, MongoDB, JavaScript, Android, Kubernetes, Docker]