A Single Organization Application in Hyperledger Fabric

In this article, I will demonstrate a Single 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.

Image for post
Image for post

Introduction

Employeeledger is a web application written in Go language to demonstrate the Hyperledger Fabric Blockchain framework. This proof-of-concept is mainly developed to upload few user records in the blockchain network and try to perform various queries from the ledger data such as Read, Update, Delete.

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

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

Installation

Employeeledger 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 variable 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 Blockchain network

Employeeledger is built on a single organization consisting of 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 complete details of a channel related to an organization.

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

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

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

./bin/configtxgen -profile EmployeeLedger -outputCreateChannelTx ./artifacts/employeeledger.channel.tx -channelID employeeledger

org1.employeeledger.anchors.tx: This artifact will allow the peers to interact with each other in a network.

./bin/configtxgen -profile EmployeeLedger -outputAnchorPeersUpdate ./artifacts/org1.employeeledger.anchors.tx -channelID employeeledger -asOrg EmployeeLedgerOrganization1

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 key at crypto-config/ORG_DOMAIN/ca/_sk file. Add the key name in the following variables at docker-compose.yaml.

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

So, all done, the Employeeledger blockchain network is now deployed into the docker containers.

Dependency Issue

  1. Hyperledger Fabric-Go-SDK is still in development. If you do dep ensure for each Gopkg.toml in EmployeeLedger 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 EmployeeLedger 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 employeeledger binary for the application.
  2. Run the employeeledger 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.
Image for post
Image for post
The User Login Page
Image for post
Image for post
The users record reading from the Hyperledger

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

I hope you find this article useful :)

Thanks

Written by

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store