Deploy a Multi Organization Blockchain Network Using Hyperledger Fabric 2.0 with NodeJS

OrderStack
3 min readJul 30, 2020

This article heavily depends on our previous article so we sincerely recommend to go through the previous article on how to Deploy a Single Organization blockchain network using Hyperledger Fabric 2.0 with NodeJS.

In the previous article on how to Deploy a Single Organization blockchain network using Hyperledger Fabric 2.0 with NodeJS, we used Hyperledger Fabric to create a network with one organization and created a channel comprising of that peer. This network is called the base network.

The base network comprises of orderer and peer nodes. In the single deployment article, we have created only a single organization. In this article, we will dive into how to add more organizations to the existing channel and record the transactions between the two organizations!

Getting Started

Create configs for the new organization

If you look at the folder structure in the HyperLedger Sample With Off-Chain Data Synchronization repository, there is a folder named additionalOrganizations under the organization directory. In that directory, if you navigate to the “org3” folder, there is a file named configtx.yaml. This file is where the config of the new organization (in our case org3) is to be written.

Run the following command to add organization to the network:

# Go to directory network/addOrgs to run this command
./addOrg.sh up -org <organization_number> -ca

The above command adds an organization to the network. The addOrg.sh file runs a series of commands which help set up the new organization.

  • up: command gets the new organization started.
  • -org: command needs a new organization_number.
  • -ca: adds the required certificates. It uses the certificate authority to generate certificates. Skipping this flag will generate default crypto config

The addOrg.sh file runs in two steps, step1Org.sh and step2Org.sh:

step1Org.sh

The file firstly fetches all the necessary configs of the existing network and generates a new config file named config.json for the new organization.

After this, the file updates the config file which takes the original and modified config and produces the config update transaction which is then signed by all the organizations of the base network in this case org1.

step2Org.sh

This file deals with letting the new organization to be added to the existing channel of the network.

The newly added organization peer tries to connect to the network and is successfully added to the channel as well.

Deploying the multi-organization network

To install the chaincode to the newly added network, we need to run the following command:

./deployCCMultiOrg.sh

This command packages the marbles chaincode and then the marbles chaincode will be installed on the peer and deployed to the channel.

Testing the Chaincode

./testCCMultiOrg.sh

This command will create a marble called marble5555 and try to read the marble data which has been committed to the chaincode. This transaction will be updated in both peers.

Clean up

Note: This command needs to be executed from the network/addOrgsdirectory

If you are finished using the sample application, you can bring down the network and any accompanying artifacts by running the following command:

./addOrg.sh -org <organization_number> down

Running the script will complete the following actions:

  • Bring down the newly added organization (In this case, org3).
  • Remove the certificates you generated by deleting the network/code/wallet folder for the new organization.
  • Delete network/code/nextblock.txt so you can start with the first block next time you operate the listener for the new organization.
  • Removes network/code/addMarbles.json for the new organization.

After this, you need to change the directory to network/scripts and run the following command to tear down the entire network:

./network.sh down

Note: The tearing down of the newly added organization is not fully implemented. There may be errors occurring even after the new organization is down. This will be rectified and updated in future releases of the system.

This seems to be it! I hope you guys learned something about blockchain and how to implement a single and multi org setup using Hyperledger Fabric and NodeJS! Stay tuned for more content!

Thanks for reading, have a productive day. Keep Coding!

--

--

OrderStack

At OrderStack, we bring to you an augmented tech team that sells engineering as a service! We work with start-ups to build bespoke MVPs.