How to setup Hyperledger fabric and work around first-network in your windows machine?-Part1

Tharindu Sandaruwan
5 min readNov 14, 2019

Firstly I am going to talk about prerequisites to set up Hyperledger Fabric on your windows machine.

Install Curl

Install the latest version of the Curl tool if you have not installed it yet.

Docker and Docker-compose

You will need to install these followings with respecting your platform which you are using with fabric-development.

  • MacOSX, *nix, or Windows 10: Docker Docker version 17.06.2-ce or greater is required.
  • Older versions of Windows: Docker Toolbox — again, Docker version Docker 17.06.2-ce or greater is required.

If you want to check the version of docker you can simply do it with this command.

docker --version  //for  docker  versiondocker-compose --version  //for  docker-compose  version

Go Programming Langauge

Hyperledger Fabric uses the Go programming language 1.12.x for many of its components.

Go-version 1.12.x

After installing, you should set the path for the go bin.

export PATH=$PATH:$GOPATH/bin

Node.js Runtime and NPM

If you will be developing applications for Hyperledger Fabric leveraging the Hyperledger Fabric SDK for Node.js, you will need to have version 8.9.x of Node.js installed. Node.js version 10 is supported from 10.15.3 and higher.

  • Node.js — version 8.9.x or greater

When installing node it automatically installs the NPM. But just ensure the version by issuing this command.

npm install npm@5.6.0 -g

Python

You need to install python 2.7. Because The Fabric Node.js SDK requires an iteration of Python 2.7 in order for npm install operations to complete successfully.

You can search version of python by issuing this command.

python --version

In windows, you have to do these extra things.

Before running any git clone commands, run the following commands:

git config --global core.autocrlf false
git config --global core.longpaths true

You can check the setting of these parameters with the following commands:

git config --get core.autocrlf
git config --get core.longpaths

These need to be false and true respectively.

For Node.js you also need the necessary Visual Studio C++ Build Tools which are freely available and can be installed with the following command:

npm install --global windows-build-tools

See the NPM windows-build-tools page for more details.

Once this is done, you should also install the NPM GRPC module with the following command:

npm install --global grpc

Now your environment is ready to go on.

Now go to the location where you want to locate the fabric-samples repository. Open bash shell there and Issue these commands.

git clone -b master https://github.com/hyperledger/fabric-samples.git
cd fabric-samples
git checkout {TAG}

To ensure the version matches of fabric binaries and fabric samples, check out to the respective tag. You can look for available tags by issuing the command git tag.

To install platform-specific fabric binaries issue these command on the terminal.

curl -sSL https://goo.gl/6wtTN5 | bash -s 1.1.0 1.1.0 0.4.6

The command above downloads and executes a bash script that will download and extract all of the platform-specific binaries you will need to set up your network and place them into the cloned repo you created above. It retrieves four platform-specific binaries:

  • cryptogen,
  • configtxgen,
  • configtxlator,
  • peer
  • orderer and
  • fabric-ca-client

And it will save those inside a bin subdirectory of the current working directory.

If you closely look at the downloaded images you would be able to see there are two images of same image ID — one tagged as “x86_64–1.x.x” and one tagged as “latest”.

Now I am going to tell you how to set up your first network using Hyperledger fabric.

Open the PowerShell in where you place your fabric-samples folder.

cd fabric-samples/first-network

Hyperledger fabric has provided a fully annotated script byfn.sh which we can use to quickly bootstrap a network which comprises of 4 peers representing two different organizations, and an orderer node. It will also launch a container to run a scripted execution that will join peers to a channel, deploy and instantiate chaincode and drive execution of transactions against the deployed chaincode.

Do you want to give a try it then follow me?

Firstly, generate crypto materials and channel artifacts. To do that use this command. Make sure you are inside the first-network folder. You will see an output like this in the terminal.

Generating certs and genesis block for with channel 'mychannel' and CLI timeout of '10'
Continue? [Y/n] y
proceeding ...
/Users/xxx/dev/fabric-samples/bin/cryptogen

##########################################################
##### Generate certificates using cryptogen tool #########
##########################################################
org1.example.com
2017-06-12 21:01:37.334 EDT [bccsp] GetDefault -> WARN 001 Before using BCCSP, please call InitFactories(). Falling back to bootBCCSP.
...

/Users/xxx/dev/fabric-samples/bin/configtxgen
##########################################################
######### Generating Orderer Genesis block ##############
##########################################################
2017-06-12 21:01:37.558 EDT [common/configtx/tool] main -> INFO 001 Loading configuration
2017-06-12 21:01:37.562 EDT [msp] getMspConfig -> INFO 002 intermediate certs folder not found at [/Users/xxx/dev/byfn/crypto-config/ordererOrganizations/example.com/msp/intermediatecerts]. Skipping.: [stat /Users/xxx/dev/byfn/crypto-config/ordererOrganizations/example.com/msp/intermediatecerts: no such file or directory]
...
2017-06-12 21:01:37.588 EDT [common/configtx/tool] doOutputBlock -> INFO 00b Generating genesis block
2017-06-12 21:01:37.590 EDT [common/configtx/tool] doOutputBlock -> INFO 00c Writing genesis block

#################################################################
### Generating channel configuration transaction 'channel.tx' ###
#################################################################
2017-06-12 21:01:37.634 EDT [common/configtx/tool] main -> INFO 001 Loading configuration
2017-06-12 21:01:37.644 EDT [common/configtx/tool] doOutputChannelCreateTx -> INFO 002 Generating new channel configtx
2017-06-12 21:01:37.645 EDT [common/configtx/tool] doOutputChannelCreateTx -> INFO 003 Writing new channel tx

#################################################################
####### Generating anchor peer update for Org1MSP ##########
#################################################################
2017-06-12 21:01:37.674 EDT [common/configtx/tool] main -> INFO 001 Loading configuration
2017-06-12 21:01:37.678 EDT [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2017-06-12 21:01:37.679 EDT [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update

#################################################################
####### Generating anchor peer update for Org2MSP ##########
#################################################################
2017-06-12 21:01:37.700 EDT [common/configtx/tool] main -> INFO 001 Loading configuration
2017-06-12 21:01:37.704 EDT [common/configtx/tool] doOutputAnchorPeersUpdate -> INFO 002 Generating anchor peer update
2017-06-12 21:01:37.704 EDT [common/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb configtx/tool] doOutputAnchorPeersUpdate -> INFO 003 Writing anchor peer update

This first step generates all of the certificates and keys for our various network entities, the genesis block used to bootstrap the ordering service, and a collection of configvgburation transactions required to configure a Channel.

You can bring the network up by issuing this command.

./byfn.sh -m up

This will up the network and install a sample go chaincode. If you want to run a command against a node chaincode issue this command.

./byfn.sh -m up -l node

To bring down the network issue this command.

./byfn.sh -m down

Then you will again prompt like this in the console.

Stopping with channel 'mychannel' and CLI timeout of '10'
Continue? [Y/n] y
proceeding ...
WARNING: The CHANNEL_NAME variable is not set. Defaulting to a blank string.
WARNING: The TIMEOUT variable is not set. Defaulting to a blank string.
Removing network net_byfn
468aaa6201ed
...
Untagged: dev-peer1.org2.example.com-mycc-1.0:latest
Deleted: sha256:ed3230614e64e1c83e510c0c282e982d2b06d148b1c498bbdcc429e2b2531e91
...

With the next part of this tutorial, I will tell you how to set up the Hyperledger fabric first-network example manually.

Thank you for reading. Follow and stay with me for more.

--

--

Tharindu Sandaruwan

Block-chain Enthusiast,React and React-native Developer,Angular developer