Nxt is one of the most impressive and under-appreciated peer-to-peer networks on the internet. It is an open-source decentralized blockchain platform that introduced a novel proof-of-stake consensus algorithm and it has survived in the wild for over 2 years. Today, the technology pioneered by Nxt is being used in well-funded projects like Ethereum, while Nxt itself remains under-the-radar.
But the Nxt developers have been very busy, and the latest release brings another set of bleeding-edge features. The API continues to expand, while the software requires minimal system resources to operate. A block-generating “full node” can run on a Raspberry Pi 2 and only costs about $50 in parts, and if you are reading this post you probably want to set up your own, so lets get started.
You’ll need the following:
- Raspberry Pi 2
- 8GB+ microSDHC card (Class 6 or higher recommended)
- Micro USB cable for power
- Cat 5 network cable or USB wifi adapter
- USB keyboard, monitor + HDMI cable (initial setup only)
Installing the OS
We will be using Linux because it is reliable, secure and free. Raspbian is the most widely used flavor of Linux for Raspberry Pi devices and it is well supported and maintained. As of this writing, the latest version of Raspbian is “Jessie” (2015-11-21), which is available for download on RaspberryPi.org. This will be a dedicated node and the client will only be accessed remotely, so I recommend using Jessie Lite since we won’t need a window manager.
There are a variety of ways to write the image to your microSDHC card and the installation guide covers Linux, OS X and Windows.
“It’s easy once you’ve done it…”
OS Configuration
Once your microSDHC card is ready, you can boot your Raspberry Pi 2 for the first time. Insert the memory card, plug in your USB keyboard, ethernet cable and HDMI connection first, then power on the Raspberry Pi 2 by plugging in the micro USB cable. Many consumer routers sold today provide a USB port that should be able to power the Raspberry Pi 2, but if you are planning to use any peripherals (e.g. USB wifi) I recommend using a 1.0A+ USB A/C adapter.
After the system boots you should see the login prompt. The default username is pi and the default password is raspberry. Once you are logged in, run the following to install the latest OS updates:
sudo apt-get update
sudo apt-get upgrade
Next, start the OS configuration utility by typing the following:
sudo raspi-config
The first thing to do is change the default password to something secure. Choose “2 Change User Password” and follow the prompts to set a new password.
Select “9 Advanced Options”
Since we aren’t using a window manager we can reallocate some of the GPU memory to the OS. Select “A3 Memory Split” and set the value to 16.
If you want to be able to access your node from another computer via SSH you can enable the service under “A4 SSH”. I highly recommend hardening your SSH installation once you have everything working.
Finally, select option “1 Expand Filesystem” to rewrite the partition table of your microSDHC card and use the full storage capacity.
Once complete, press ESC to exit raspi-config and reboot your system:
sudo reboot
After logging in again, check and confirm that the root filesystem mounted on / has been expanded:
df -h
The size of the root filesystem should be close to the size of your microSDHC card.
Filesystem Size Used Avail Use% Mounted on /dev/root 15G 2.2G 13G 14% /
Next we are going to increase the swap space by editing the swap configuration file and restarting the service:
sudo nano /etc/dphys-swapfile
Modify the line for CONF_SWAPSIZE and set it to 512 or 1024 and save the file (CTRL-O, ENTER, CTRL-X).
# set size to absolute value, leaving empty (default) then uses computed value # you most likely don't want this, unless you have an special disk situation CONF_SWAPSIZE=1024
Restart the swapfile service:
sudo service dphys-swapfile restart
Network Configuration
Since this will be a full node, you will need to allow peer-to-peer network traffic through your router firewall. Every network configuration is different so this section is going to be more of a general guideline. Assuming you are connected to a router with DHCP enabled, your Raspberry Pi 2 should already have a local IP address, otherwise you will need to configure a static IP address. To show your current network configuration:
ifconfig eth0
eth0 Link encap:Ethernet HWaddr b1:ff:4a:a4:ff:1b inet addr:192.168.1.10 Bcast:192.168.1.255 Mask:255.255.255.0
inet addr is your local IP, HWaddr is your MAC address. In your router configuration, find the port forwarding settings and forward TCP/UDP traffic for port 7874 to the local IP address of your Raspberry Pi 2. If you aren’t using a static IP address, you should set up a DHCP static lease (aka DHCP reservation) for the MAC address and the local IP address. This way the Raspberry Pi 2 will always get the same local IP address that you configured with the port fowarding rule.
Installing Java
Nxt requires Java 8. You can download and manually install the Oracle JRE, or you can easily install the OpenJDK JRE:
sudo apt-get install openjdk-8-jre
Confirm that Java is installed correctly by checking the version:
java -version
You should see an output similar to this:
openjdk version "1.8.0_40-internal" OpenJDK Runtime Environment (build 1.8.0_40-internal-b04) OpenJDK Zero VM (build 25.40-b08, interpreted mode)
Installing Nxt
Download the latest version of Nxt from the public repository. You can use the wget command in the console to directly download the file over HTTPS. As of this writing the current Nxt release is version is 1.7.4, but you will want to make sure you are using the latest version available.
wget https://bitbucket.org/JeanLucPicard/nxt/downloads/nxt-client-1.7.4.zip
Check the hash of the package and verify that it matches the hash in the signed release notes. You can also verify the hash in the blockchain. The Nxt account used by lead core developer Jean Luc is NXT-X4LF-9A4G-WN9Z-2R322.
sha256sum nxt-client-1.7.4.zip
baf0286983fee3f718ea755dd76f5e9bb3d6a2962560368d513ffc9517d10c9b nxt-client-1.7.4.zip
Extract the archive to create the “nxt” directory:
unzip nxt-client-1.7.4.zip
Before configuring Nxt, you will need to find out your public IP address. You can do so with the following command:
curl ipinfo.io
Take note of your public IP address and then run the following command to create a new configuration file:
nano ~/nxt/conf/nxt.properties
The following is an example configuration file:
nxt.myAddress=12.34.56.78 nxt.apiServerHost=0.0.0.0 nxt.allowedBotHosts=*
If you were able to configure port forwarding on your router, set nxt.myAddress to your public IP address as shown in the output of the curl command, otherwise remove this line from the configuration file. For the other parameters, we’ve set the API to allow connections from everywhere. Once you have things working, you should consider restricting access to your local network or specific IP addresses. See nxt/conf/nxt-default.properties for descriptions of configuration parameters. Save the configuration file and exit the editor.
Edit the startup file and optimize the memory configuration:
nano ~/nxt/run.sh
Add the parameter -Xmx640m to increase the default the Java heap memory allocation to 640mb:
java -Xmx640m -cp classes:lib/*:conf nxt.Nxt
You are now ready to start the server. Since this is a fresh installation, your node will need to download the entire blockchain to synchronize with the Nxt network. In some cases, this can take a very long time depending on the speed of your network connection and the type of memory card you are using.
Startup & Connect
Nxt runs as a server process that provides an API and a web client interface. First, start the server:
cd ~/nxt
./run.sh
You should see the Nxt server start up and synchronize with the network. When startup is complete you will see the following:
2016-01-03 13:43:28 INFO: Nxt server 1.7.4 started successfully. 2016-01-03 13:43:28 INFO: Copyright © 2013-2016 The Nxt Core Developers. 2016-01-03 13:43:28 INFO: Distributed under GPLv2, with ABSOLUTELY NO WARRANTY. 2016-01-03 13:43:28 INFO: Client UI is at http://localhost:7876/index.html
Open a web browser on a PC connected to the same network navigate to the local IP of the Raspberry Pi 2 on port 7876.
Example: http://192.168.1.10:7876
For the interactive API interface, append /test to the url.
Example: http://192.168.1.10:7876/test
Congratulations, if you are able to access the login / test page your Nxt installation is successful. To stop the Nxt server, press CTRL-C at the console.
Final Steps
Enable SSL
Before you can safely use Nxt, you should setup SSL on your node. If you use HTTP, a attacker on your network may be able to steal your passphrase. I highly recommend configuring a self-signed cert for your node and using HTTPS only. I posted some “cheat sheet” instructions that are based on the instructions in the wiki. Core developer Riker has also posted a thread on setting up SSL.
Install screen
To make management of your node easier, I recommend installing screen. It will let you run programs in detachable sessions, and once you start using it you’ll wonder how you missed it for so long.
sudo apt-get install screen
To use screen on your Nxt server, edit run.sh and modify the command:
nano ~/nxt/run.sh
screen -mS nxt java -Xmx640m -cp classes:lib/*:conf nxt.Nxt
The next time you start the server using run.sh, you will be able to detach from the process by pressing CTRL-A, CTRL-D. To re-attach the session, enter the command:
screen -r nxt
Auto startup
An easy way automatically start the Nxt server at boot is with the cron task scheduler. You need to add an entry specifying @reboot and run your startup commands there:
crontab -e
@reboot sleep 30 && cd /home/pi/nxt && ./run.sh
In this example the Nxt server will startup on boot after a 30 second delay. You can use cron to schedule other tasksas well.
For questions or comments, please visit the forum thread for this blog post.