-
Check Hyperledger Fabric version 2.2 -> v2.2
-
Check Hyperledger Fabric version 2.5 (currently in development) -> v2.5
- Download or check the required dependencies: Dependencies
-
Make sure to remove
hyperledgerdirectory (if present) under/vardirectory on our system. -
Run this script to install all fabric binaries of specific version mentioned in script.
./loadFabricDependencies.sh- Check new folders created by this script ->
binandconfigdirectories.
π 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_SampleNetworkAppdirectory will be ourproject_hometo follow further step.
cd FabricV2_SampleNetworkApp- Now we run this script from
project_hometo 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
organizationsdirectory.
- Next we run this script from same
project_hometo createcrypto-materialsfor peers, orderers and other participating entities.
./scripts/registerEnroll.sh- Check out
ordererOrganizationsandpeerOrganizationsdirectories underorganizationsdirectory containing all crypto-materials related to ourpeersandorderers.
- 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 twoconnection-org1.jsonandconnection-org1.yamlfiles containing all connection details of our Peer nodes.
- Next we create genesis block of our network.
./createFirstGenesisBlock.sh- Check out
system-genesis-blockdirectory containinggenesis.blockfile.
- Now finally we start our network to build and run our
peers,orderers,couchDBand 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/hyperledgerdirectory (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.
- Now next we create our network
channelrelated files and join peers to this newly created channel.
./scripts/createChannel.sh- Check out
channel-artifactsdirectory containing 3 files :anchorandchannelrelated.txfiles and also.blockfile of channel.
-
Now comes the
chaincodepart i.e. oursmartcontract, beginning with fabric 2.x version new chaincode methodology i.e. 4 stage lifecycle process is introduced, this involves1.package,2.install,3.approvethen finally4.commitstages in the chaincode deployment process.- Currently two chaincode types are supported based on language types i.e.
NodeandGo (Golang). - We need to edit the
deploySmartContract.shscript file for selecting which chaincode we are going to deploy and use. There are some variables related tochaincode_language,chaincode_pathandchaincode_namepresent 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
.envfile present in./organizations/clientOrg/appdirectory and comment or uncomment variables related tochaincode_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.
- Currently two chaincode types are supported based on language types i.e.
./scripts/deploySmartContract.sh- Check the Smartcontract tar file will be created at
packagingstage. - Also check out new
dev-peer containersbuilt up and running there are known aschaincode containerswith their specificsmartcontract versions.
- (OPTIONAL STEP) : For testing chaincode invocation. This will check if chaincode is working via
peer chaincode invokecommand. Also edit thechaincode_namevariable in this script based on our chaincode type before executing.
./scripts/invokeContract.sh- Check if invoked transaction is
committedorfailed- if successfully committed then chaincode is fine and ready to handle request by our application.
- Now we change our directory to this
./organizations/clientOrg/appdirectory 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 startIf server start smoothly without showing any error then -
- Check out
./organizations/clientOrg/app/identitydirectory containingwalletidentities for ouradminanduser. These are generated as identities for our client application. - This newly created user identity generated via
fabric CAwill 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
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.shNow 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.
Syncing On Chain blocks data to Off Chain database for following below purpose -
- Handle
complex queries. - To create
analyticsandstatisticaldashboard therefore handle itsrepeated query loadvia 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.10Then 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.
Application Server: Node, Express, JS
Blockchain Backend: Hyperledger Fabric, SmartContract, Docker, Shell Script
If you have any feedback, please reach out to me at vikashbatham97@gmail.com
If you loved my work then please leave a Star β to this Repository.
