A Dogecoin Widget for Geckoboard

by James on 20th February 2014

Dogecoin

Geckoboard is a slick real-time widget dashboard that pulls data from a bunch of SaaS platforms; think all your realtime Google Analytics, Mixpanel, Twilio, Twitter, Facebook stats displayed on one big screen.

We wanted a widget on our Geckoboard showing the live balance of a Dogecoin address: DShDeWzfKWP37jAgedeH1ExJEQR93Czxm4. By mashing-up a simple node.js script, the DogeChain API, and a custom Geckoboard push widget we created:

Dogecoin Widget

No very stylish, but it gets the job done! Keep reading for the steps to build-your-own DOGE widget!

The DogeChain API exposes an endpoint addressbalance where we can fetch the balance of our address. For example:

$ curl "http://dogechain.info/chain/Dogecoin/q/addressbalance/DShDeWzfKWP37jAgedeH1ExJEQR93Czxm4"
1000%

We need to pipe this balance into Geckoboard. Geckoboard doesn't have a built-in widget for this purpose, so we will use a custom number widget. In Geckoboard select Custom Widgets

Select Custom Widget

then Number & Secondary Stats.

Select Number and Secondary Stat Widget

Give your widget an appropriate label and set its update method to PUSH. Widget Push Config A Geckoboard PUSH widget will update every time you POST a specially formatted JSON request to its Push URL. Make note of the Widget Key as we need it in the next step.

First we include the request library: It gives us a simple interface for making HTTP requests. Next we specify our target DogeCoin public address, our GeckoBoard API key (available in your Account Details), and our Widget Key (as noted above).

var request = require('request');

// Update and push the current balance every 30 seconds.
var UPDATE_INTERVAL = 30000;

// Our Dogecoin public address.
var DOGECOIN_PUBLIC_ADDRESS = 'DShDeWzfKWP37jAgedeH1ExJEQR93Czxm4';

// Our Geckoboard API key and widget specific key.
var GECKOBOARD_API_KEY = 'YOUR_GECKOBOARD_API_KEY_HERE'
  , GECKOBOARD_WIDGET_KEY = 'YOUR_GECKOBOARD_WIDGET_KEY_HERE';

// Push endpoint for our Geckoboard widgets.
var GECKOBOARD_PUSH_URL =
    'https://push.geckoboard.com/v1/send/' + GECKOBOARD_WIDGET_KEY;

// DogeChain address balance endpoint.
var DOGECHAIN_BALANCE_URL =
    'http://dogechain.info/chain/DogeCoin/q/addressbalance/' + DOGECOIN_PUBLIC_ADDRESS;

Our update function simply pulls the address balance, converts it from a String to a Number, then packs it into a payload object suitable for the Geckoboard push widget API. We log any errors, if any of these operations fail we simple wait another 30 seconds until the next retry.

function update() {
  console.log('Fetching...');

  // Fetch our address balance from DogeChain.
  request.get(DOGECHAIN_BALANCE_URL, function(err, res, body) {
    if (err) {
        console.error(err);
    } else {

      // Build a Geckboard push widget payload.
      var payload = {
        api_key: GECKOBOARD_API_KEY,
        data: {
          item: [
            { text: 'Balance', value: Number(body) }
          ]
        }
      };

      // Push our address balance to Geckoboard.
      request.post(GECKOBOARD_PUSH_URL, { json: payload }, function(err, res) {
        if (err) {
          console.error(err);
        } else {
          console.log('Updated.');
        }
      });
    }
  });
}

Finally we do an initial update and then poll the update function every 30 seconds.

update();
setInterval(update, UPDATE_INTERVAL);

Combine this all into a script and put it on a server somewhere in the cloud. Run the script and BAM, your Geckoboard widget is now showing your DogeCoin address balance in near real-time. All code in this post is available at https://github.com/BroApp/geckoboard-dogechain.

Challenge: Create a custom css style for your Geckoboard widget. The default style is not very Doge friendly.