How to use ARK Blockchain REST API with Node-Red

This guide will provide detailed instructions on how to install and use Node-Red to read blockchain data provided by the ARK Public REST API.

A simple example application is provided that queries the delegate API endpoint and sends an alert to your phone when the delegate’s rank has changed.

The ARK Public Network powered by ARK Core uses DPoS(delegated proof of stake) consensus, making it one of the fastest, efficient, and scalable Blockchain networks available today.
ARK has created a suite of easy to use open source wallets and tools which make it easy to launch your own sovereign blockchain. ARK’s Deployer tool) removes the heavy lifting making the deployment of your blockchain simple and quick.

Documention for the ARK Public REST API can be found here:
https://ark.dev/docs/api/public-rest-api/getting-started

Node-RED is a low-code programming environment for event-driven applications. It uses flow-based programming to let you draw a visual representation of how messages should flow through the application. Developers can quickly create meaningful applications without having to write a lot of code. Node-Red is one of my favorite applications for prototyping IoT and Blockchain applications.
If you have just basic programming type background you will be able to easily start working with Node-Red and create a meaningful application. There is also a very large community so there are many examples and tutorials.

This guide is written for installation on Raspberry Pi 4 running Ubuntu 21.10 however setup would be nearly identical on a basic VPS. A $5/month VPS from Digital Ocean would be great for this project.

There is a Node-Red hosted service called FRED that includes a free version that will get you up and running very quickly if you don’t want to run your own instance of Node-Red.

Table of Contents

    1. Install Ubuntu Server 21.10

    See this guide for a secure basic installation of Ubuntu 21.10.

    2. Install Node-Red (Tested with Version 2.1.4)

    See this guide for installation of Node-Red

    3. Getting started with Node-Red

    If you are new to Node-Red then I recommend starting with this tutorial to learn about the development environment with some basic examples.
    https://nodered.org/docs/tutorials/first-flow

    You will also find lots of tutorials when searching online and on Youtube. Version 2 of Node-Red was released in the summer of 2021. There were quite a few new features and improvements since Version 1 so older tutorials might have some slightly different options in the dev environment.

    4. Retrieve Relay Node’s Status via Internet Browser

    This simple example will retrieve the status of the ARK relay node that we will use to retrieve blockchain data.
    For our testing we are going to use the following public ARK relay: https://api.ark.io

    To view the node’s status we can call the following API using any internet browser:
    https://api.ark.io/api/node/status
    You should get a similar result formatted as a JSON packet:

    5. Retrieve Relay Node’s Status via Node-Red

    We will now do the same API call using Node-Red. To do this we need an inject, http request and debug nodes wired up like the following:

    Double click the http request node and enter https://api.ark.io/api/node/status in the URL field.

    Now you can save and start the flow by pressing the Deploy button.

    Open the debug tab on the right side of the editor and then press the tab on the left side of the inject node. You should see the response to the http request in the debug tab.

    6. Retrieve wallet info via Node-Red

    Now we will change the API call so that we can retrieve info about a wallet. In this example we will use our Delegate’s wallet.
    Change the url in the http request node to the following: https://api.ark.io/api/wallets/AYucu8vZqerWkvHGYBhDv8dJ8qAN4tw77N

    Deploy the flow and press the inject tab as before. You should see a similar JSON string as the result:

    For more complicated flows often we want to work with a Javascript object instead of the JSON string. There is a json node that makes this very easy. Add a json and debug node to the flow like the following:

    You should see the same packet converted to an object when you run the flow.

    7. Monitor Delegate’s Rank and send message to Pushover app when rank has changed

    Install Pushover App on your device

    I really like using the Pushover app to receive alerts or notification from my IoT and Blockchain projects. Apps are available for Android, iPhone and desktop. It has a one time $5 cost but it is well worth it in my experience.

    1. Create an account on https://pushover.net/
    2. Install the app on your device and login to account
    3. Open your account on browser (https://pushover.net/)
      1. At the top of the page there is your secret User Key. Record this.
      2. At the bottom of the page there is section called Your Applications. Create a new application/API token. Call it Delegate Monitor.
      3. Record the generated API Token/Key (keep it secret)

    Install Pushover Node in Node-Red

    Install this node which provides API interface to Pushover app: node-red-contrib-pushover
    See this link for guide to installing new nodes:

    Import Example Flow

    I have created an example flow that periodically retrieves our ARK delegate’s rank and will send an alert to pushover when it changes.
    Download this example flow from the following link and import it into Node-Red
    https://gateway.pinata.cloud/ipfs/QmS6uH3qWEW7XL3Ugk4ZVgucwLboXqLdUH4t7fStASN193

    Use this guide for help with importing flows.
    https://nodered.org/docs/user-guide/editor/workspace/import-export

    Once you have imported the flow then you will need to configure the pushover node with the secret keys you recorded previously. Double click on the blue send to pushover node. Press the edit icon by the keys property. You can then enter your User key token and application/API token

    Deploy the flow and it should look like this:

    The flow will query the delegate API every 10 minutes and if the rank changes it will send an alert to the Pushover App on your device. This is how the notifications look on my Android device.

    drawing