There have already been articles published on the use cases for using IoT with a private Blockchain. The possibilities are really exciting but what if we could run the blockchain ON our IoT network. That sounds like a fun project to me!
With that goal in mind and a bit of research I was led to Hyperledger Fabric. To learn more about it check this out: Hyperledger Overview. Getting Hyperledger Fabric to run on Raspberry Pi presented several major hurdles:
- No one had compiled the project for the ARM architecture before.
- There wasn’t any documentation on how to run the Hyperledger on a Docker Swarm.
But hurdles are what make projects fun right? So lets go through the steps so that you can setup your own.
- Setting up a Hyperledger Fabric development environment on a Raspberry Pi
- Building Hyperledger Fabric on Raspberry Pi
- Setting up a Docker Swarm on Raspberry Pi
- Deploying a Hyperledger Fabric network on the Swarm with Docker Stack and testing with BYFN.
Lets get started!
Setting up a Hyperledger Fabric development environment on a Raspberry Pi
Setup your Raspi
For this project I used Raspbian Lite (who needs a GUI am I right!) . Download and follow the install guide for your OS on raspberrypi.org. I originally did this on Jessie but since Stretch is out I’m testing it with the latest build I’m doing while updating my documentation and this series. So the instructions below apply to Stretch.
Then you’ll need to do some pretty standard initial setup for your RasPi, run raspi-config, change default password, enable SSH, config your keyboard, set the timezone, advanced -> change memory split to 16MB… etc. Once the basic config is done it’s time to get it online. You can use an ethernet cable or follow this guide to setup wifi. Also once you have a network connection established use can use SSH, personally I usually do this so I don’t need to “hand jam” all the commands and can just C&P. You can also copy your private key on your computer to you RasPi so you no longer need a password. When I do this I usually create a new user:
sudo adduser *username*
sudo usermod -aG sudo *username*
After you do the standard stuff I always recommend updating & upgrading:
sudo apt-get update
sudo apt-get dist-upgrade
Setup your development environment
Install the Go programming language:
Hyperledger was built and tested using Go version 1.7.5… so says the documentation (at time of writing – March 9th, 2018). I’ve tried using 1.10, 1.9.4, 1.9.3 and 1.8.7 recently and they all had some issues. Go v1.8.7 build suffer form this issue: https://github.com/golang/go/issues/23739. So I’m going to recommend using Go 1.7.5 since we are targeting a HL v1.0 build. As I learned you need to make sure you target the correct branch for the build you are targeting.
THE VERSION OF GO YOU USE WITH THE BUILD YOU ARE TARGETING IS CRUCIAL.
sudo tar -C /usr/local -xzf go1.7.5.linux-armv6l.tar.gz
sudo echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile
sudo echo 'export GOPATH=$HOME/go' >> ~/.profile
curl -sSL https://get.docker.com | sh
Install Docker Compose
curl -s https://packagecloud.io/install/repositories/Hypriot/Schatzkiste/script.deb.sh | sudo bash
Install Required Libraries
sudo apt-get install git python-pip python-dev docker-compose build-essential libtool libltdl-dev libssl-dev libevent-dev libffi-dev
Install Python Libraries
sudo pip install --upgrade pip
sudo pip install --upgrade setuptools
sudo pip install behave nose docker-compose
sudo pip install -I flask==0.10.1 python-dateutil==2.2 pytz==2014.3 pyyaml==3.10 couchdb==1.0 flask-cors==2.0.1 requests==2.4.3 pyOpenSSL==16.2.0 pysha3==1.0b1 grpcio==1.0.4
Reboot & Test
Make sure you actually reboot or re-login to your RasPi otherwise you’ll get nothing from the go version or path (since they were added to your bash profile).
(should be something like /home/user/go)
All of the above commands should output the version or the required software. If they do no you missed something.
If you are getting any errors while installing any libraries please reference the current documentation for Hyperledger.
Anyway… now that we have our development environment setup it’s time to start the build. Check out my next article for the details on this next step.
20 thoughts on “Hyperledger Fabric v1.0 on a Raspberry Pi Docker Swarm – Part 1”
i came as far as Install Python Libraries
raspberry pi3 and stretch (with desktop)
-sudo pip install –upgrade pip
-sudo pip install -I .. 1.0.4
File “/usr/lib/python2.7/dist-packages/pip/req/req_install.py”, line 82, in __init__
req = Requirement(req)
File “/usr/share/python-wheels/packaging-16.8-py2.py3-none-any.whl/packaging/requirements.py”, line 94, in __init__
requirement_string[e.loc:e.loc + 8]))
error: command ‘arm-linux-gnueabihf-gcc’ failed with exit status 1
Command “/usr/bin/python -u -c “import setuptools, tokenize;__file__=’/tmp/pip-build-yuRTRJ/cffi/setup.py’;f=getattr(tokenize, ‘open’, open)(__file__);code=f.read().replace(‘\r\n’, ‘\n’);f.close();exec(compile(code, __file__, ‘exec’))” install –record /tmp/pip-ZcQK3q-record/install-record.txt –single-version-externally-managed –compile” failed with error code 1 in /tmp/pip-build-yuRTRJ/cffi/
I’ll dig back into my build documentation because I don’t remember that issue. I’ll try and publish another article on this soon.
Found the problem I needed to wrap my code block in the post because the double hyphen was getting converted to a single long one. The post has been updated 😀 . Thanks for the feedback.
IBM Oracle SAP are using Hyperledger Fabrik.Banks are deploying it to 8 countries.
The is now a oracle sandbox .
Something to explore for me in 2018. !
Could you please let me know when are you planning to publish the next steps.
Really interessting article. Did you successfully install hyperledger on the raspberry pi? I would love some more articles about it
Yes I did and ran a full simulation. I’ve been meaning to do a video and write more about it… but I got pulled into other things. Maybe your interest is just the kick I needed to get back to this. Thanks!
Hi joe, I am eagerly waiting for your video. I found this article very interesting
Thanks Mohit! Well post two is almost finished. The image build has required some finagling since things on the hyperledger end have gotten a bit out of date but it’s coming along.
Hey Joe, your tutorial would prove quite useful for a few of my university projects. Hopefully you will have something in store for us soon!
Just did these instructions and all fine so far.
Planning to deploy part 2 soon?
It’ll be published once I get a successful build and I’m almost there. I have just a few more issues to work out.
Great work bro, I have a question, I installed everything on the Rapsberry pi 3,Docker is running fine for hello-world program, but when i further go for hyperledger network, It gives me error “Error response from daemon: manifest for not found ”
I tried to solve this issue, Do you have any Idea
Thanks in advance
Hmmm… I haven’t experienced that issue myself. What exactly are you trying to do with the network?
I am just trying to run fabric-samples first network, to check everything is fine.
I am getting this error
E: Sub-process /usr/bin/dpkg returned an error code (1)
Hi, thanks for all of this, i can build my own byfn based on all of your information above, great work bro,
And can you share your python code and instalation steps as seen as on your video,please. just for learning purposes
The python scripts are here: https://github.com/Cleanshooter/hyperledger-pi-composer/tree/master/python-scripts
As for running the scripts you would run them the same way you would run any python script… I’m not sure how to explain it better. Sorry.
Hello my friend is 2020 this fabric hyperledger to raspberry pi still works?
No idea I haven’t touched hyperledger for a while now…