Step by Step Towards Hyperledger Fabric — Part 1

in blockchain •  7 years ago  (edited)

Blockchain is the new buzz word in the industry now a days. But finding good resources to learn this fascinating technology is not a cake walk. To make it easier for others i am starting a series in the field of Blockchain/ DLT platforms. I will try to cover each and every step require to get a hands on these technologies. Firstly, I am starting with Hyperledger Fabric.

Blockchain-Technology-Courses-Trainings-That-Will-Accelerate-Your-Career.jpg

Hyperledger Fabric is one of the projects under Hyperledger umbrella.
Hyperldger is platform for distributed ledger solutions, underpinned by a modular architecture delivering high degrees of confidentiality, resiliency, flexibility and scalability.

Lets start over first Step by Step hands on:

Firstly we have to learn how to install the prerequisite for the Hyperledger Fabric:
o Install cURL.
o Instll Node.js and npm package manager.
o Install Go Language.
o Install Docker and Docker Compose.
o Install Git.
o Install Pip
o Install Hyperledger Fabric on Ubuntu LTS 16.0.4

Once we are done with installing prerequisite, we will be going to hands on with:

  1. Build & Deploy your first-network on Hyperledger Fabric
  2. Build & Deploy a demo example Fabcar on Hyperledger Fabric

We are using Ubuntu LTS 16.04 for this hands on tutorial:

Step 1:
Press Ctrl + Alt + T to open a terminal
$ sudo su
Enter your password
$ cd

Step 2: Install Google golang
$ cd $HOME/ && wget https://storage.googleapis.com/golang/go1.8.1.linux-amd64.tar.gz
1.png

$ tar -xvf go1.8.1.linux-amd64.tar.gz
2.png

2.1.png

Set the go path
$ mkdir $HOME/gopath
$ export GOPATH=$HOME/gopath
$ export GOROOT=$HOME/go
$ export PATH=$PATH:$GOROOT/bin
$ go version

3.png

Step 3: Install libltdl-dev
$ apt-get install libltdl-dev
4.png

Step 4: Install docker-­ce
$ wget https://download.docker.com/linux/ubuntu/dists/xenial/pool/stable/amd64/docker­-ce_17.06.0~ce­-0~ubuntu_amd64.deb5.png

$ dpkg ­i docker-­ce_17.06.0~ce-­0~ubuntu_amd64.deb
6.png

$ docker -­ -­version
7.png

Note: The above approach simply leverages the Docker images that the Hyperledger Fabric project publishes to Docker Hub

$ docker run hello­-world
8.png

Step 5: Installl python-­pip
$ apt-­get install python­-pip
9.png

$ pip ­- -­version
10.png

Step 6: Install docker­-compose
$ pip install docker­-compose
$ docker­-compose ­- -­version
11.png

Step 7: Install git
$ apt­-get install git
$ git ­-­ -version
12.png

Step 8: Install curl
$ apt-­get install curl
$ curl ­- -version
13.png

Step 9: Install node.js and npm
$ curl ­sL https://deb.nodesource.com/setup_8.x | sudo ­-E bash ­-
14.png

14.1.png

$ node -­ -­version
$ npm ­- -version

Screenshot from 2018-04-28 03-05-49.png

Step 10: Clone the fabric-­samples from the github
$ git clone https://github.com/hyperledger/fabric-­samples.git
16.png

Step 11: Enter the fabric-­samples directory and install the platform specific binaries
$ cd fabric-­samples
$ curl -­sSL https://goo.gl/byy2Qj | bash -­s 1.0.5
17.png

17.1.png

17.2.png

$ docker images
17.3.png

If everything goes well you will see the above output on your screen.

Step 12: To have a look on the download binaries execute the following from your terminal:
$ cd bin
$ ls

18.png

Step 13: Enter into the first-network directory
$ cd ../
$ cd first-network
$ ls19.png

Step 14: Generate the required certificates and articates for your first network
$ ./byfn.sh -m generate

20.png

20.1.png

20.2.png

Step 15: To see the generate certificates use the following command:
$ ls
$ cd crypto-config
$ ls

21.png

Step 16: Create your first network using the following command
$ cd ../
$ ./byfn.sh -m up

22.png

22.1.png

22.2.png

22.3.png

22.4.png

22.5.png

22.6.png

You will see the above message once your first-network is created using Hyperledger Fabric.

Step 17: Check the generates images and running containers using the following command:
$ docker images
$ docker ps

23.png

Step 18: To bring down the created network executed the following command
$ ./byfn.sh -m down

24.png

24.1.png

Step 19: You can check the created images have been removed using the following:
$ docker images
25.png

We have successfully created our first-network using Hyperledger Fabric.

Now lets try another example

Step 20: Move to the fabcar directory
$ cd ../
$ ls
$ cd fabcar

26.png

Step 21: Install the node modules using the following command
$ sudo npm install
27.png

27.1.png

Step 22: Install grpc module for communication with Hyperledger Fabric using the following command:
$ sudo npm install grpc
28.png

28.1.png

Step 23: Start the Hyperledger Fabric network for fabcar by executing the following command:
$ ./startFabric.sh

29.png

29.1.png

Step 24: To enroll the users firstly you have to enroll an Admin that will help to enroll other users with
Hyperledger Fabric network of Fabcar.
$ node enrollAdmin.js

30.png

You can find the private and public key for admin using the following
$ ls
$ cd hfc-key-store/
$ ls
31.png

Step 25: Enroll the user to query and invoke fabcar network (As Hyperledger Fabric is a permissioned
blockchain that is why firstly we have to register the user using its certificate)
$ cd ../
$ node registerUser.js

32.png

Step 26: Query the Fabcar network using the following command (To access the ledger state)
$ node query.js
33.png

Step 27: Now lets try to submit a new record for our Fabcar application on top of Hyperledger Fabric
$ gedit invoke.js
34.png

Make the below changes in the file above to create a new record:
35.png

Step 28: Now invoke the transaction using the below command. (To make any changes in the ledger state we have to invoke function)
$ Ctrl + c
$ node invoke.js
36.png

Step 29: Query the ledger to find the changes made by you using the following
$ node query.js
37.png

Congrats to all for successfully running Fabcar demo. In the next part i will going to cover technical details on these two examples that we have covered. If you have any specific topic want to cover for these two examples make a comment to include it.

Stay tuned for more updates!

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!