Getting started with hyperledger-fabric
My current domain, Supply Chain & Container Logistics, is buzzing with various Blockchain use cases, pilots, and even production-grade deployments.
Enterprise Blockchain (not cryptocurrency) I believe has finally bloomed out of its academic thesis/research papers cocoon to its crucial commercial acceptance form. Every now and then we are coming across new articles, blogs, whitepapers on how Enterprise blockchain is adding value to use cases in finance, supply chain, and other domains.
With that in mind and a spoiling amount of choices, I figured hyperledger-fabric to the best bet for beginners. Few points in its favors:-
- Completely dockerized. Runs seamlessly in Windows Docker Desktop
- fabric-samples is so easy to use and understand
- Bringing up the test-network is child’s play
- Using the existing SmartContracts and Applications is straightforward
- The abundance of language support. That is something else.
Steps
To get the latest and greatest run this on Git bash (prereqs)
curl -sSL https://bit.ly/2ysbOFE | bash -s
This will download latest -
- fabric-samples code base
- fabric binaries
- fabric docker images — peer, ca, tools, orderer
Change directory to fabric-samples/test-network folder
Use this profiles script for CLI -
source local.profiles.env 1
Bring up the network by-
./network.sh up -ca
Create the default channel (mychannel)-
./network.sh creteChannel
Deploy a sample chaincode(Smart Contract)
./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-javascript/ -ccl javascript
Run the corresponding application
cd ../asset-transfer-basic/application-javascript
npm install
node app.js
For bringing down the test network-
./network.sh down
Use the below script for deep cleanup-
./fullCleanupPostTestNetworkDown.sh
What just happened ?
The above commands installed required binaries, docker images, scripts to get started with Hyperledger-fabric Blockchain. Then the “network.sh” script allowed us to create conveniently a couple of organizations, their cryto(ca) materials and initiated the docker images for running a test blockchain network (all under the hoods). Further using the same script a channel (DLT) between two organizations and a sample chaincode(Smart Contract) to transfer a digital asset from one owner to another was successfully installed and demoed.
In this test-network you can go ahead and even add another organization — Org3MSP using the scripts under addOrg3 folder in fabric-samples/test-network/addOrg3
Blockchain Explorer
To have a more viusal confirmation on what just happened explorer is a great simple easy to use tool.
Create a explorer folder parallel to fabric-samples folder.
Download the files as mentioned in this configuration step-
$ wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/main/examples/net1/config.json
$ wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/main/examples/net1/connection-profile/test-network.json -P connection-profile
$ wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/main/docker-compose.yaml
Edit network name in docker-compose.yaml from net_test to fabric_test to match the fabric test network.
Edit the name of admin certificate and secret key in test-network.json to match the one under -
../fabric-samples/test-network/peerOrganizations/org1.example.com/users/ Admin@org1.example.com/msp/keystore/*_sk
../fabric-samples/test-network/peerOrganizations/org1.example.com/users/ Admin@org1.example.com/msp/cacerts/*cert.pem
Bring up the docker containers for explorer-
docker-compose -f docker-compose.yaml up -d
To check logs ( if required)
docker-compose -f docker-compose.yaml logs
To login to the docker container ( if required)
winpty docker exec -it explorer.mynetwork.com //bin//sh #for windows
Once explorer is up go to — http://localhost:8080/#/
Lets connect back latter where we do more complex and customized things on hyperledger fabric.