Creating a Hyperledger Composer Application on Windows 10 Home
System Requirements
Before we begin working on anything Hyperledger related we need to get our environment setup, below are the prerequisites required:
Operating Systems: Ubuntu Linux 14.04 / 16.04 LTS (both 64-bit), or Mac OS 10.12
Docker Engine: Version 17.03 or higher
Docker-Compose: Version 1.8 or higher
Node: 8.9 or higher (note version 9 is not supported)
npm: v5.x
git: 2.9.x or higher
Python: 2.7.x
A code editor of your choice, visual studio preferred
Setting Up WSL (Windows Subsystem Linux)
As you can see above the required operating system is Linux, but don’t fret, Windows 10’s latest edition has Linux Subsystem (WSL — Windows Subsystem Linux). You can set that up on your computer by following the steps below:
- Go to Windows Features by typing that in your Windows 10 search box or via Control Panel > Programs
- Check the box Windows Subsystem for Linux and hit OK
3. Install the Ubuntu app from the Microsoft Store
4. Launch the Ubuntu app and start scripting!
Check out Michael Treat’s guide to WSL for a deeper understanding on WSL
Running Pre-Requisite Download Script on WSL
- Open up your Ubuntu app and run the following commands:
curl -O https://hyperledger.github.io/composer/latest/prereqs-ubuntu.sh
chmod u+x prereqs-ubuntu.sh./prereqs-ubuntu.sh
You might come across the Error: Ubuntu bionic is not supported hyperledger composer. To fix this go into the script (you can do nano prereqs-ubuntu.sh) and change
declare -a version=('trusty' 'xenial' 'yakkety');
' todeclare -a version=('trusty' 'xenial' 'yakkety' 'bionic');
Now re-run prereqs-ubuntu.sh script
Setting up Docker on you Windows
Unfortunately, Docker for Windows doesn’t work on Windows Home so you’ll need to use Docker Toolbox. You can download and install it using this link (https://docs.docker.com/toolbox/toolbox_install_windows/).
Create a Docker Default Machine
Once it’s installed, open up Docker Quickstart Terminal and create a new docker-machine machine. Run the command below to create your machine:
docker-machine create default
Now you can see your docker machine default running docker-machine ls
Enabling Docker API access to your WSL
Now you can have to call the docker api so your WSL can communicate with it.
- In your Docker Quickstart Terminal go into your docker ssh by running
docker-machine ssh
2. Go into your boot2docker by running the command cd /var/lib/boot2docker folder
3. Edit your profile by typing sudo vi profile
4. Change Docker_TLS to no, your profile should have the following lines:
EXTRA_ARGS=’
— label provider=virtualbox‘
CACERT=/var/lib/boot2docker/ca.pem
DOCKER_HOST=’-H tcp://0.0.0.0:2376'
DOCKER_STORAGE=aufs
DOCKER_TLS=no
SERVERKEY=/var/lib/boot2docker/server-key.pem
SERVERCERT=/var/lib/boot2docker/server.pem
5. Exit the ssh by typing exit
6. Restart your docker machine by typing docker-machine restart
7. Once it’s back up, check to see if you can access the API
Can you see the JSON at the following URL?
http://dokerMachineIp:2375*/containers/json?all=1
- Replace this with your docker machine’s ip address and port, you can get this by running docker-machine env
Connecting WSL to Windows Docker
Go into Docker and enter the command docker-machine env
Go into your WSL and set the environmental variables by copying the lines that are displayed in the Docker window, all except DOCKER_CERT_PATH
Installing Fabric in WSL
This step gives you a local Hyperledger Fabric runtime to deploy your business networks to.
In a directory of your choice (we will assume ~/fabric-dev-servers), get the .tar.gz file that contains the tools to install Hyperledger Fabric:
mkdir ~/fabric-dev-servers && cd ~/fabric-dev-serverscurl -O https://raw.githubusercontent.com/hyperledger/composer-tools/master/packages/fabric-dev-servers/fabric-dev-servers.tar.gztar -xvf fabric-dev-servers.tar.gz
A zip is also available if you prefer: just replace the .tar.gz file with fabric-dev-servers.zip and the tar -xvf command with a unzip command in the preceding snippet.
Use the scripts you just downloaded and extracted to download a local Hyperledger Fabric v1.2 runtime:
cd ~/fabric-dev-serversexport FABRIC_VERSION=hlfv12./downloadFabric.sh
Starting Fabric
You control your runtime using a set of scripts which you’ll find in ~/fabric-dev-servers if you followed the suggested defaults.
The first time you start up a new runtime, you’ll need to run the start script, then generate a PeerAdmin card:
cd ~/fabric-dev-serversexport FABRIC_VERSION=hlfv12./startFabric.sh./createPeerAdminCard.sh
You can start and stop your runtime using ~/fabric-dev-servers/stopFabric.sh, and start it again with ~/fabric-dev-servers/startFabric.sh.
At the end of your development session, you run the following commands:
~/fabric-dev-servers/stopFabric.sh~/fabric-dev-servers/teardownFabric.sh
Note that if you’ve run the teardown script, the next time you start the runtime, you’ll need to create a new PeerAdmin card just like you did on first time startup.
Start web-app Playground
To start the web app, run:
composer-playground
It will typically open your browser automatically, at the following address: http://localhost:8080/login
You should see the PeerAdmin@hlfv1 Card you created with the createPeerAdminCard script on your “My Business Networks” screen in the web app: if you don’t see this, you may not have correctly started up your runtime!
Creating Project Structure
In WSL go to the location where you would like to save your project and run the following command:
yo hyperledger-composer:businessnetwork
Setup IDE
Install VSCode from this URL: https://code.visualstudio.com/download
Open VSCode, go to Extensions, then search for and install the Hyperledger Composer extension from the Marketplace
Voila! You’re ready start you’re first Hyperledger Fabric application on Windows!