Install Hyperledger Fabric V2.2 & Run Test Network 🚀
Errors covered | with each step snapshot | bring up HF network fast
Before starting this article, let me give you some context about it. In this article we will install Hyperledger Fabric and run test-network
with clean and minimal steps, we will also look into possible errors that might lead you to scratch your head for hours if you don’t read this.
This article will hold your hand from zero to bring up network, If you want to intensify each term, I will highly recommend you to read KC Tam’s 👉 ( this ) article after completing this one, to understand how exactly things work in detail.
Before installing fabric samples make sure you have installed all the prerequisites
Quick Note: Refer my Golang artical to set golang environment 👇
To first install the fabric-sample run this command to install :
curl -sSL https://bit.ly/2ysbOFE | bash -s --2.2.0 1.4.9
Fabric v2.3.0 is released but we will go with v2.2.0 ( as it is stable) and 1.4.9 is fabric CA version
This curl
script will clone fabric-samples repo and pull Hyperledger Fabric binaries.
It will only pull the images that did not exist and will use prev images ( if you have used fabric before )
If script successfully run then it will show all the images that you pulled, and will look like this —
Now, navigate to test-network
to check its properly installed or not and we will do some operation ( init, invoke ) on test-network.
cd fabric-samples/test-network
To start nice & fresh, run this command to tear down artifacts, crypto material, containers and chaincode images from previous runs to avoid unwanted error.
./network.sh down
Now we are ready to bring our network up by running—
./network.sh up
test-networks has two members i.e. Org1 & Org2. Each Org has two peers and One Orderer maintain the ordering service. We will able to see two peers and one orderer if we run —
docker ps -a
Now we will create channel between Org1 and Org2, peer will also join the same channel ( default channel name : mychannel
), if we run —
./network.sh createChannel
You will find follwing message, if it’s successful
Lets deploy our chaincode, the script will install the chaincode dependencies if you are deploying it for first time —
./network.sh deployCC
🐞 It will fail if you do not set your GOROOT path and will say somthing like this —
Lets resolve this my setting GOROOT path ( do this only if you faced above ERR )
Refer this, If you still facing errors 💁
export PATH=${PWD}/../bin:$PATH
&
export FABRIC_CFG_PATH=$PWD/../config/
To initialize the ledger run in your terminal—
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"InitLedger","Args":[]}'
result will look like this, if command is successful —
List the ledger by running this query —
peer chaincode query -C mychannel -n basic -c '{"Args":["GetAllAssets"]}'
if successful, output will look like this —
Command to change the owner by invoking asset-transfer chaincode —
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n basic --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"function":"TransferAsset","Args":["asset6","Christopher"]}'
respones if its successful—
query the asset-transfer (basic) chaincode running on peer0.org2.example.com
peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","asset6"]}'
Result showing asset6
transferred to Chirstoper —
If you made it to the end, then you have installed HF, run test-network
, and also perform some operation on chaincode.
Now to tear down the test network, run —
./network.sh down
Congratulations 🤜🤛 you installed the fabric-samples and tested first network
Thank You for reading 🍃
Also, Read
- The Best Crypto Trading Bot
- Deribit Review | Options, Fees, APIs and Testnet
- FTX Crypto Exchange Review
- Bybit Exchange Review
- The Best Bitcoin Hardware wallet
- Crypto Copy Trading Platforms
- The Best Crypto Tax Software
- Best Crypto Trading Platforms
- Best Crypto Lending Platforms
- Ledger Nano S vs Trezor one vs Trezor T vs Ledger Nano X
- BlockFi vs Celsius vs Hodlnaut
- Bitsgap review — A Crypto Trading Bot That Makes Easy Money
- Quadency Review- A Crypto Trading Bot Made For Professionals
- PrimeXBT Review | Leverage Trading, Fee and Covesting
- HaasOnline Review and Get a 10% discount
- Ellipal Titan Review
- SecuX Stone Review
- BlockFi Review | Earn up to 8.6% interests on your Crypto
- Best Crypto APIs for Developers
- Best Blockchain Analysis Tools
- Crypto arbitrage guide: How to make money as a beginner
- Top Bitcoin Node Providers
- Best Crypto Charting Tool
- What are the best books to learn about Bitcoin?