If you have a Raspberry Pi lying around and fancy seeing if you can get the Hashgraph sdk running on it, here is how.

Step 1: Check if Java is present and if it is 1.8+

If you are running Raspbian Stretch, it will have Java 8 already on it. Otherwise you’ll have to download it at  Oracle

The location of Java on the Pi is: /usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt

Step 2: Get the sdk

Run:
> wget https://www.swirlds.com/downloads/Swirlds%20SDK%20-%20version%2018.05.23.zip
If you try running the sdk:

> jav -jar swirlds.jar

and get this error:

The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE

Make sure you have set JAVA_HOME correctly. To set it run:

> nano ~/.profile
and add this line at the bottom of the file:
export JAVA_HOME=/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt
Take care of arm32 if you copied the command from another website.

Test by running:
> echo $JAVA_HOME
> /usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt

Step 3: Download JCE

If you try and run it now, you’ll probably get this error:

***************************************************************************
* ERROR: Please install the Oracle JCE Unlimited Jurisdiction Policy files.
* They can be downloaded as a single .zip file from:
*     http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html
* If that address doesn't work, then click on the DOWNLOAD button 
* next to the JCE Unlimited Strength link in the Additional Resources 
* section of this page:
*     http://www.oracle.com/technetwork/java/javase/downloads
* Then unzip the downloaded .zip file, and move the two .jar files into:
*      /home/pi/Downloads/sdk/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/lib/security
* Please make sure they are legal in your country before installing.
***************************************************************************

Download Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files 8 from here and paste it to /usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/lib/security.

Now it should work but you’ll get null pointer exception errors.

This is because the code is trying to execute console.out.println(“Hello Swirld from “ + myName); at line 68 and it can’t because there is no console. Go into the source file and comment this out with //. Do this for line 91 as well. 

Now it should work but you won’t see anything happening. If you run top, you should see Java consume 200% cpu but that is about it. The problem is that you’ve ssh’d into your Pi and there is no output console. To see some output, try step 4.

Step 4: Getting funky

Go to sdk/source/HelloSwirldDemo/src and modify HelloSwirldDemoMain.java and add a system.out.println as shown below.

#console.out.println("Hello Swirld from " + myName);
System.out.println("Hello Swirld from " + myName);

Step 5: Installing Maven

Check if you have maven with:

pi@raspberrypi:~ $ mvn -v
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T19:49:05Z)
Maven home: /opt/apache-maven-3.5.3
Java version: 1.8.0_65, vendor: Oracle Corporation
Java home: /usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "4.9.59-v7+", arch: "arm", family: "unix"

If you don’t get the above then download Maven first:
> wget http://www-us.apache.org/dist/maven/maven-3/3.5.3/binaries/apache-maven-3.5.3-bin.tar.gz
Extract to /opt:

> cd /opt
> sudo tar -xzvf /path/to/apache-maven-3.5.3-bin.tar.gz

Then you need to tell shell where to find maven. We’ll do this in the system profile settings so it is available to all users.

> sudoedit /etc/profile.d/maven.sh

and enter

export M2_HOME=/opt/apache-maven-3.2.5
export PATH=$PATH:$M2_HOME/bin

Source: https://xianic.net/2015/02/21/installing-maven-on-the-raspberry-pi/

Step 6: Compiling with Maven

Go back to the HelloSwirldDemo folder where there is a pom.xml file. Run:

mvn install

It can take anywhere between 20 seconds to 7 minutes….

Output

Here is a quick video sped up 20x:

Leave a Reply

Your email address will not be published. Required fields are marked *