Skip to content

vikash-ftw/Hyperledger-Fabric-v2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

115 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Hyperledger Fabric 2.x versions list

  • Check Hyperledger Fabric version 2.2 -> v2.2

  • Check Hyperledger Fabric version 2.5 (currently in development) -> v2.5

Fabric Architecture Overview

Fabric_Architecture

Steps to Run Fabric Network Locally

Fresh Setup on Ubuntu Machine

  1. Make sure to remove hyperledger directory (if present) under /var directory on our system.

  2. Run this script to install all fabric binaries of specific version mentioned in script.

./loadFabricDependencies.sh
  • Check new folders created by this script -> bin and config directories.

πŸ“ Note: We can generate certificates and cryptographic key pairs (crypto-materials) that authenticate and authorize entities on the network via cryptogen (For testing and development purpose) or Fabric CA (For Production purpose) - We will use Fabric CA in our case.

πŸ“ Note: From now onwards for all the below steps our FabricV2_SampleNetworkApp directory will be our project_home to follow further step.

cd FabricV2_SampleNetworkApp
  1. Now we run this script from project_home to start fabric-ca containers needed for crypto-materials.
./scripts/start_fabric-ca.sh
  • Check new fabric ca containers will be up and running.
  • Also check fabric-ca (volume mapped data directory for fabric-ca containers) created under organizations directory.
  1. Next we run this script from same project_home to create crypto-materials for peers, orderers and other participating entities.
./scripts/registerEnroll.sh
  • Check out ordererOrganizations and peerOrganizations directories under organizations directory containing all crypto-materials related to our peers and orderers.
  1. Next run this script to create CCP(Common Connection Profile), this will be needed by application to connect with network.
./organizations/ccp-generate.sh
  • Check out ./organizations/peerOrganizations/org1.example.com/ directory having these two connection-org1.json and connection-org1.yaml files containing all connection details of our Peer nodes.
  1. Next we create genesis block of our network.
./createFirstGenesisBlock.sh
  • Check out system-genesis-block directory containing genesis.block file.
  1. Now finally we start our network to build and run our peers, orderers, couchDB and other network containers.
./scripts/start_network.sh
  • Check out new peers, orderers, couchDB and other network containers building up and running.
  • Also check out /var/hyperledger directory (volume mapped data directory for all our peers, orderers and couchDB containers)
  • Make sure none of the containers enters the 'Exited' state. Wait for approximately 5-8 seconds, then check the status of the containers.
  1. Now next we create our network channel related files and join peers to this newly created channel.
./scripts/createChannel.sh
  • Check out channel-artifacts directory containing 3 files : anchor and channel related .tx files and also .block file of channel.
  1. Now comes the chaincode part i.e. our smartcontract, beginning with fabric 2.x version new chaincode methodology i.e. 4 stage lifecycle process is introduced, this involves 1.package, 2.install, 3.approve then finally 4.commit stages in the chaincode deployment process.

    • Currently two chaincode types are supported based on language types i.e. Node and Go (Golang).
    • We need to edit the deploySmartContract.sh script file for selecting which chaincode we are going to deploy and use. There are some variables related to chaincode_language, chaincode_path and chaincode_name present in this script, so we just need to comment and uncomment based on these factors.
    • After deploying chaincode we need to use chaincode in our SDK application developed in Node, for that just edit the .env file present in ./organizations/clientOrg/app directory and comment or uncomment variables related to chaincode_name.
    • These changes needed to be done beforehand so that specific chaincode can be deployed and used.
    • By Default Node based chaincode configs are applied everywhere.
./scripts/deploySmartContract.sh
  • Check the Smartcontract tar file will be created at packaging stage.
  • Also check out new dev-peer containers built up and running there are known as chaincode containers with their specific smartcontract versions.
  1. (OPTIONAL STEP) : For testing chaincode invocation. This will check if chaincode is working via peer chaincode invoke command. Also edit the chaincode_name variable in this script based on our chaincode type before executing.
./scripts/invokeContract.sh
  • Check if invoked transaction is committed or failed - if successfully committed then chaincode is fine and ready to handle request by our application.
  1. Now we change our directory to this ./organizations/clientOrg/app directory to run our application.
cd organizations/clientOrg/app
  • Installation of node modules packages. (Node version must be v20.14)
npm i
  • Finally start our node server.
npm start

If server start smoothly without showing any error then -

  • Check out ./organizations/clientOrg/app/identity directory containing wallet identities for our admin and user. These are generated as identities for our client application.
  • This newly created user identity generated via fabric CA will now be used by out application to invoke chaincode.
  • Finally our client app is ready to handle request and invoke chaincode so now test the application.

To access the CouchDB ledger UI on browser go to http://localhost:5984/_utils/#

Fabric CA Certificate Renewal - Document

Additional AddOn Features

Hyperledger Explorer

An interactive and real-time visualizations of our fabric blockchain and its data related insights in a user-friendly manner.

Run this script from FabricV2_SampleNetworkApp directory -

./scripts/start_explorer.sh

Now we can access the Explorer UI on browser with port 8080.

If facing any error in accessing Explorer UI then check the container logs of explorer via docker logs <container_name/Id> command, there are two explorer containers one for explorer database and another one for main explorer. So check the main explorer container with name explorer.mynetwork.com and image name ghcr.io/hyperledger-labs/explorer.

On Chain to Off Chain Data Sync

Syncing On Chain blocks data to Off Chain database for following below purpose -

  • Handle complex queries.
  • To create analytics and statistical dashboard therefore handle its repeated query load via Off Chain database. This reduces the On Chain ledger network load.

First Run the mongodb in a Dockerized way.

docker run -d -p 27017:27017 -v /var/mongo_offchaindb/:/data/db --name mongo_offchaindb mongo:8.0.10

Then edit this Enviroment variable - ALLOW_OFFCHAIN_SYNC in a .env file at app directory (FabricV2_SampleNetworkApp/organizations/clientOrg/app/.env) by default this variable is set to false to set it true. Now stop the node server and run it again after saving these changes.

Here MongoDB will run on the port 27017.

To view the data on GUI then checkout Compass, download and install - MongoDB_Compass

In case if we are running our own full non dockerized version of mongodb then we need to edit OFFCHAIN_MONGODB_ADDRESS environment variable in same .env file.

Tech Stack

Application Server: Node, Express, JS

Blockchain Backend: Hyperledger Fabric, SmartContract, Docker, Shell Script

Authors

Feedback

If you have any feedback, please reach out to me at vikashbatham97@gmail.com

Stars 🌟

If you loved my work then please leave a Star ⭐ to this Repository.

Stars

About

A Hyperledger Fabric v2.x single-node setup with Node and Go based smart-contracts support with CouchDB as state database, also additional functionality includes Hyperledger Explorer integration and Off-chain data sync.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors