Tutorials
No Results
Tutorial

Intermediate · 1 hour

Development on Algorand using Raspberry Pi - Part 2

This is the second in a multi-part tutorial series focusing on the Raspberry Pi, an inexpensive desktop computer. In the previous tutorial, we setup the Raspberry Pi (RPi) and configure remote access using SSH. In this tutorial, we will install the Algorand software, configure algod as a participation node and install our first software development kit (SDK). In the next tutorial we will use the fully configured RPi development environment to begin developing Algorand solutions.

You will learn:

  • What types of nodes comprise the Algorand network
    → Relay, archival, participation nodes
  • How to install and configure Algorand software
    → The variety of networks Algorand offers
    → How to join a network
    → How to manage your participation keys
  • Basic management of an active node
  • Installation of the Algorand JavaScript SDK on RPi

Requirements

  • Raspberry Pi (needs at least 4GB of RAM and 100GB storage to be a viable node, requirements )
  • Raspberry Pi OS install and configured for remote access (see Part 1)
  • Recommended to use heat sink or fans on the Raspberry Pi.

Info

During the fast catchup operation, you may experience CPU throttling due to higher temperature of CPU. It will settle after the ~10 minutes, once the node catches up on the blocks.

Background

Algorand network relies on Nodes that are used in various modes of operation. Participation nodes contribute to the consensus mechanism, which plays a significant role in network security - as long as 2/3 of nodes are honest, the network is secure. This tutorial shows how to set up such a node and join the network.

To have an active node, we have to generate participation keys. These keys have to be rotated periodically, as they can only be valid for finite duration. Therefore, keep in mind the following regarding the management of participation keys and your node in general:

  • In case your participation keys are not valid, mark your node offline.
  • In case you have technical issues, mark your node offline.
  • If you want to renew the participation keys, you can pre-sign multiple key transactions but do not back up the generated participation key. Sign transactions offline.
  • Keep an eye on the node and verify it’s working well, otherwise mark offline.

Secondly, the node can be used for development, where we communicate with it and it serves as a gateway to the rest of the Algorand network. Therefore, we also set up a couple of valuable tools used in the upcoming tutorials.

Steps

We assume you have a Raspberry Pi running with SSH remote access to it. In case your RPi is not ready, navigate to Tutorial Part 1.

Step 1 - Install Algorand software and start the node

  1. SSH to your RPi from the host machine ssh [email protected]
  2. Create a directory in your home directory mkdir ~/node
  3. Navigate to it cd ~/node
  4. Download Algorand software:
    • Download with following command: wget https://raw.githubusercontent.com/algorand/go-algorand-doc/master/downloads/installers/update.sh
    • Change permissions on the update script chmod 544 update.sh
    • Run the script to update/download latest version ./update.sh -i -c stable -p ~/node -d ~/node/data -n
  5. (Optional) Start a telemetry data collection to provide feedback to Algorand developers ./diagcfg telemetry enable
  6. Development is best performed on TestNet. Therefore, we create a testnetdata node setup
    • Make a new directory for the testnet node mkdir ~/node/testnetdata
    • Copy configuration file cp ~/node/genesisfiles/testnet/genesis.json ~/node/testnetdata
  7. Start our first node on the TestNet network and check its status
    • ./goal node start -d ~/node/testnetdata
    • ./goal node status -d ~/node/testnetdata
  8. Your node is behind the blockchain, to catch up, we use the fast catch-up option offered by Algorand
    • Download the latest checkpoint for testnet: wget https://algorand-catchpoints.s3.us-east-2.amazonaws.com/channel/testnet/latest.catchpoint
    • Create a variable:CATCHUP_POINT=$(cat latest.catchpoint)
    • Fast catchup: ./goal node catchup $CATCHUP_POINT -d ~/node/testnetdata
  9. This will take approximately 10 minutes. Wait until you catch up on the blocks. You can check a live status: ./goal node status -d ~/node/testnetdata -w 1000
    • -w is in miliseconds
  10. (Optional) In case you want to run your node in an archival mode, follow these steps:
    • NOTE: You need at least 500GB of storage to run node in this mode of operation to store the whole Algorand Blockchain.
    • Copy the config file cp config.json.example testnetdata/config.json
    • Modify the config file vi testnetdata/config.json
    • Search for Archival: false and change to true
    • Stop and start your node again, so the changes take affect
    • Wait for the node to catchup (will take some time…)

Step 2 - Create an account and make the node online

After Step 1, we have a node running and it caught up on blocks using fast catchup of the last checkpoint. Now we join the TestNet!

  1. Create a wallet and an account:
    • New wallet: ./goal wallet new MyWallet -d ~/node/testnetdata
    • New account: ./goal account new -d ~/node/testnetdata
    • List created account with 0 balance: ./goal account list -d ~/node/testnetdata
  2. Fund your new account with algos from dispenser
    • Navigate to dispenser https://bank.testnet.algorand.network/
    • Solve CAPTCHA and fill in your account public address.
    • Algos are on its way
  3. Check status (./goal node status -d ~/node/testnetdata) of the blocks on your node and pick a point when your participation key should be valid from. Make sure it is in the future; rule of thumb approx 300 blocks ahead to current round.
  4. Create a participation key:
    • ./goal account addpartkey -a <address-of-participating-account> --roundFirstValid=<partkey-first-round> --roundLastValid=<partkey-last-round> --keyDilution=<key-dilution-value> -d ~/node/testnetdata
    • <partkey-first-round> defines the starting point of validity of the key and <partkey-last-round> the end block.
    • key-dilution-value can be computed as a square root of range of participation key valid period.
    • List if key is created successfully: ./goal account listpartkeys -d ~/node/testnetdata and its details: ./goal account partkeyinfo -d ~/node/testnetdata
  5. Create a key registration transaction and sign it:
    • Format of key registration transaction: ./goal account changeonlinestatus --address=<address-of-participating-account> --fee=2000 --firstvalid=<transaction-first-round> --lastvalid=<transaction-last-round> --online=true --txfile=online.txn -d ~/node/testnetdata
    • <transaction-first-round> defines the starting point validity of the transaction and <transaction-last-round> the last valid block. Maximum difference is 1000 rounds.
    • Sign it: ./goal clerk sign --infile=online.txn --outfile=online.stxn -d ~/node/testnetdata
  6. Wait until the blocks reach the scope of your <partkey-first-round> and send the transaction:
    • Rawsend of the signed transaction: ./goal clerk rawsend --filename=online.stxn -d ~/node/testnetdata
    • It takes approx. 320 rounds to see the effect
    • if you are lucky, your node will participate in the consensus: grep 'VoteBroadcast' ~/node/testnetdata/node.log
  7. Congrats, your node is online!

Keep in mind the rules for management of the participation keys mentioned in Background.

Step 3 - Install development tools and Algorand JavaScript SDK

In these steps we install some useful prerequisites for development, which will be used in the upcoming tutorials. Namely, Python3, NodeJS, and Algorand JavaScript SDK.

Info

The RPi may be configured to use any/all of the available SDKs for development. Please reference the Workspace Setup guide for installation details for the SDK of your choosing.

  1. Start with installation of NodeJS. Navigate to nodejs required for the Javascript SDK
    • Always start with update sudo apt-get update
    • We choose the LTS (long term support) of NodeJS curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
    • Start with installation sudo apt-get install -y nodejs
    • Verify the proper version is installed (14.x.x) node -v
  2. Next we can install the JavaScript AlgoSDK
    • Run npm install algosdk
    • JavaScript AlgoSDK is installed
  3. Finally, we install Python3.9. On the RPi is recommended manual installation - official package is behind the latest version of Python.
    • Start with an update, as usual sudo apt-get update
    • Install pip3 sudo apt install python3-pip
    • Install dependencies sudo apt-get install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev
    • Navigate to cd /usr/src
    • Download source sudo wget https://www.python.org/ftp/python/3.9.2/Python-3.9.2.tgz
    • Extract the files sudo tar -xf Python-3.9.2.tgz
    • Start with installation after navigating to cd Python-3.9.2
    • Prepare ./configure --enable-optimizations
    • Install sudo make altinstall
    • Prepare simlink sudo ln -s /usr/local/bin/python3.9 /usr/local/bin/python3
    • Running python3 should show python3.9.2
    • Cleanup installation files in /usr/src
      • sudo rm -Rf Python-3.9.2
      • sudo rm Python-3.9.2.tgz

Next Steps

You have successfully installed the Algorand software on your RPi, configured it as a participation node and configured it as a development environment with NodeJS and the Algorand JavaScript SDK. Continue on to the next tutorial to begin developing solutions on Algorand.

python

security

transactions

JavaScript

goal

run a node

SDK

participate

March 25, 2021