Hyperledger Fabric 2.2 Tutorial
Overview
This article shows how to setup a Hyperledger Fabric Network (HLF) v2.2, deploy chaincode, invoke, and query chaincode. We first give a high-level walk-through of the process, and later use Test Network provided in HLF examples to demonstrate the whole process. The script provided in Test Network makes bringing the blockchain Network along with Fabric CA servers much easier and we can use the crypto-material to perform the demonstration.
Check out my course on Hyperledger Fabric Deployment on MultiHost
High-level Walk-through
- Generating crypto-material from the organizations and orderer (Org1, Org2, and Orderer) using Fabric CA server.
- Generating channel artifacts eg. system channel genesis block, channel transaction, channel genesis block, etc,).
- Updating anchor peers.
- Creating a channel.
- Joining the channel.
- Deploying chaincode on the channel.
- Invoke or query the chaincode.
Prerequisites
- Golang
- Docker
- Nodejs
Bring Up Network
Here we first download the HLF binaries along with fabric examples. We will be using the Test network provided in the fabric examples. Our network will consist of Two Organization with one peer each, One orderer node, Three CA server (one for each organization and third for orderer), Two couchdb instances for state database(one for each peer)
1. Download the fabric binaries.
curl -sSL https://bit.ly/2ysbOFE | bash -s -- 2.3.0 1.4.9
2. Set the environment variable
cd fabric-samples && export PATH=$PWD/bin:$PATH
3. Once step 2 is completed, go to the test-network folder.
cd test-network
4. Run the command and pass the options according to your need. To check all the available options run ./network.sh help
5. To start the network with Fabric CA Servers, CouchDB and creating a channel mychannel
.
-ca
: Use Certificate Authorities to generate network crypto material-c
: Name of channel to create (defaults to"mychannel”
)-s
: Peer state database to deploy:goleveldb
(default) orcouchdb
up
— Bring up Fabric orderer and peer nodes. No channel is created.up createChannel
: Bring up fabric network with one channel.createChannel
: Create and join a channel after the network is created
./network.sh up createChannel -ca -c mychannel -s couchdb
if everything goes well that at the end you can see something like this.
we have completed step 1 to step 5 in the High-level Walk-through section of this article.
6. Next step to deploy chaincode, in the example repository there are multiple chaincode
-ccn
: Chaincode name. This flag can be used to deploy one of the asset transfer samples to a channel. Sample options: basic (default), ledger, private, sbe, secured-ccl:
Programming language of the chaincode to deploy:go
(default),java
,javascript
,typescript
-verbose:
Verbose mode
You can explore all the available options in the help section
./network.sh deployCC -ccn basic -ccl go -verbose
once the chaincode deployment is successful you will get output like this
7. Now over chaincode deployment is done and we will now invoke and query the chaincode. we will be using nodejs SDK to interact with the blockchain network.
cd ../asset-transfer-basic/application-javascript && npm install
node app.js
This script will register the user appUser into the FileSystemWallet and will invoke the InitLedger function of the chaincode and this function will create 6 records into the ledger. After this it call the function GetAllAssets and this function returns all the records stored in the ledger, we can access the CouchDB via the fauxton UI ( peer0.org1=> http://localhost:5984/_utils/# and peer0.org2=> http://localhost:7984/_utils/#). After that it call CreateAsset which add a new record into the ledger.
And we have out HLF network up and running.
Summary
I hope this article provides insight into Setting up Fabric Network v2.2 using the Fabric CA Servers along with CouchDB as the state database.
Join Coinmonks Telegram group and learn about crypto trading and investing
Also, Read
- What is a Flash loan?
- The Best Crypto Trading Bot | Grid Trading
- 3Commas Review | Pionex Review | Coinrule review
- AAX Exchange Review | Deribit Review |FTX Crypto Exchange Review
- NGRAVE ZERO review
- Bybit Exchange Review | Bityard Review | CoinSpot Review
- 3Commas vs Cryptohopper
- The Best Bitcoin Hardware wallet | BitBox02 Review
- Ledger vs Ngrave | ledger nano s vs x
- Crypto Copy Trading Platforms | Bityard copy trading
- Vauld Review | YouHodler Review | BlockFi Review
- The Best Crypto Tax Software | CoinTracking Review
- Best Crypto Lending Platforms
- Ledger Nano S vs Trezor one vs Trezor T vs Ledger Nano X
- BlockFi vs Celsius | Hodlnaut Review
- Bitsgap review | Quadency Review
- Ellipal Titan Review | SecuX Stone Review
- DEX Explorer | Blockchain APIs | LocalBitcoins Review
- Best Blockchain Analysis Tools
- Crypto arbitrage guide: How to make money as a beginner
- Best Crypto Charting Tool | Best Crypto Exchange
- What are the best books to learn about Bitcoin?