Summary: Hyperledger Fabric has become a leading platform on which to deliver blockchain solutions. In this post, we will focus on installing the Hyperledger Fabric examples on a VM (Ubuntu 18.04), running in EXSi 6.7 on a Dell R710. We will not go over creating the VM, but will assume that we are at the “vanilla post install” phase prior to any updates or package installs.
Audience: Primarily directed towards developers who want to get the preliminary example set up and running with the intent, for example, of plugging in a test front end for further exploration.
Languages: Javascript
Author: Robert Bell
Useful Links:
- https://hyperledger-fabric.readthedocs.io/en/release-1.4/build_network.html
- https://hyperledger-fabric.readthedocs.io/en/release-1.4/write_first_app.html
- https://docs.docker.com/
1) Update the server environment:
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo reboot
Note: I am not setting up a firewall in this example.
2) (Optional) I like to set the date and install emacs:
$ sudo timedatectl set-timezone America/Los_Angeles
$ sudo apt-get install emacs25-nox
3) Install Node and NPM:
$ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
$ sudo apt-get install -y nodejs
Note: We will be using Hyperfabric 1.4, which only supports Node.js 8.x.
4) Install Golang:
$ sudo apt-get install golang
5) Install Docker and Docker Compose:
$ curl -sSL https://get.docker.com/ |sh
$ sudo usermod -a -G docker $USER
$ sudo systemctl start docker
$ sudo systemctl enable docker
$ sudo reboot
$ sudo curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
$ chmod +x /usr/local/bin/docker-compose
Important Note: See https://github.com/docker/compose/releases for the latest version of Docker Compose command.
6) Install the Hyperledger Fabric samples:
(Optional) $ mkdir fabric
(Optional) $ cd fabric
$ curl -sSL http://bit.ly/2ysbOFE | bash -s
7) Run “./byfn.sh generate” and test the network:
$ cd ./fabric-samples/first-network
$ ./byfn.sh generate
$ ./byfn.sh up -l node
You’ll see a lot of output, finally ending in something like this (unless there are errors):
========= All GOOD, BYFN execution completed ===========
_____ _ _ ____
| ____| | \ | | | _ \
| _| | \| | | | | |
| |___ | |\ | | |_| |
|_____| |_| \_| |____/
Note: If you want to check the containers are up, run the following…
$ docker container list
8) Bring down the network:
$ ./byfn.sh down
9) Let’s now run the Fabcar example:
$ cd ../fabcar/
$ ./startFabric.sh javascript
$ cd javascript
$ npm install
$ node enrollAdmin.js
$ node registerUser.js
$ node query.js
——
Ok, now what? Well, assuming you have encountered no errors, you’ll have a network up and running. Take a look through query.js, and start working backwards through the code (for example, plug in your own front end and start invoking some of the calls). The best way to learn is to try. Things will undoubtedly fail, but that’s when you learn the most. You’ll find lots of useful information on the websites for Hyperledger Fabric, including detailed explanations on smart contracts and other concepts central to blockchain.
One point to keep in mind: If installing all of this on the Windows Subsystem for Linux (WSL), make sure that the appropriate ports are set up in Docker for Windows so that the VM can punch through the barriers appropriately. Also, it seems that the installation path matters when dealing with WSL. It’s best to setup an automount for /c and then put all of the containers/fabric directories in the windows-visible area (e.g. /c/fabric)
Excellent point, Erik!
You can also use the “sudo mount –bind /mnt/c /c” in WSL to make sure paths are resolved correctly when starting up the network in that case.
This was incredibly instructive – thanks for putting it out there.
I had an easy time following it – and even took a chance on digging a bit deeper into the various components.