Get in Touch
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
twitter logodiscord logo
close icon
Code

How to ACTUALLY make the Hyperledger test-network docs work

Bradley Woolf

Background

Hyperledger is a complicated animal, hence the managed services that have come out such as Chainstack and AWS Managed Blockchain for Hyperledger. This extends to their docs, where spinning up a network requires a series of docker commands and scripts. You'll see lots of code flying by on your Terminal, which will make you feel like you're in a Hollywood hacking movie.

In this tutorial, you'll set up a Dockerized network on your local machine, where two organizations (nodes) will share data between each other through chaincode (a smart contract). I'll be on a Mac.

Getting started

I'll be setting this up to be Javascript focused. Follow the docs to install Docker, Node, and any other env dependencies (https://hyperledger-fabric.readthedocs.io/en/release-2.2/test_network.html).

I'm just going to paste the steps that worked for me. Start by going to whatever directory you are comfortable with and creating a /hyperledger directory.

  • mkdir hyperledger
  • cd hyperledger
  • curl -sSL https://bit.ly/2ysbOFE | bash -s -- 2.2.2 1.4.9 
  • cd test-network
  • touch test-network/docker/.env

At this point, you need to create a .env file via the above command, and in the test-network/docker folder, put in three env variables:

  • COMPOSE_PROJECT_NAME=net
  • IMAGE_TAG=latest
  • SYS_CHANNEL=system-channel

Copy/paste without the bullets, and there is no need for commas in a .env file.

Create a .env file in the test-network/docker folder, and create three env variables: COMPOSE_PROJECT_NAME=net, IMAGE_TAG=latest, SYS_CHANNEL=system-channel

Here are the rest of the commands, though you can follow the remainder of the tutorial. Make sure you are in /test-network:

  • ./network.sh up createChannel -c mychannel -ca       
  • ./network.sh deployCC -ccn basic -ccp ../asset-transfer-basic/chaincode-javascript/ -ccl javascript
  • export PATH=${PWD}/../bin:$PATH
  • export FABRIC_CFG_PATH=$PWD/../config/

Commands for setting up the first organization (Org1) and interacting with it:

  • export CORE_PEER_TLS_ENABLED=true
  • export CORE_PEER_LOCALMSPID="Org1MSP"
  • export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
  • export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
  • export CORE_PEER_ADDRESS=localhost:7051
  • 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":[]}'

Command for transferring ownership, will become relevant for the second organization:

  • 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"]}'

Commands for setting up the second organization (Org2) and interacting with it:

  • export CORE_PEER_TLS_ENABLED=true
  • export CORE_PEER_LOCALMSPID="Org2MSP"
  • export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
  • export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
  • export CORE_PEER_ADDRESS=localhost:9051

Test if the asset was transferred correctly:

  • peer chaincode query -C mychannel -n basic -c '{"Args":["ReadAsset","asset6"]}'

Shut down the network:

  • ./network.sh down

Wrap up

Public blockchains are the obvious choice for the future of our financial infrastructure- whether it be insurance, sending money, or building the decentralized internet. But, if governments, government entities, healthcare systems, and private financial institutions are going to adopt blockchain as a means of infrastructure and data storage, private chains like Hyperledger are going to be needed.

Want to accept all ERC20's and network tokens?
Get in touch