Justin Welch avatar

Pulling wallet (and other) profile data from steemit.com/@username.json using javascript

justinw

Published: 03 Jun 2017 › Updated: 03 Jun 2017Pulling wallet (and other) profile data from steemit.com/@username.json using javascript

Pulling wallet (and other) profile data from steemit.com/@username.json using javascript

steemnode.png

Did you know that steemit.com's front-end (condenser) serves profile data for use in other applications via JSON? Check it out, example: steemit.com/@username.json. Just fill in your username and go.

SBD, STEEM, and VESTS balances are available in addition to quite a bit more.

steemit.com serves content in gzip compressed format, so you do need to load a library and pipe it in order to get valid JSON - easy enough.

I'm sure some of you will find this useful :)

This is an example and it just displays a few objects, but it's as simple as this:

const https = require('https');
const zlib = require('zlib');

let options = {
    host: 'steemit.com',
    path: '/@username.json'
};
    
https.get(options, function (res) {
    let json = '';
    let gunzip = zlib.createGunzip();
    res.pipe(gunzip);
    gunzip.on('data', function (chunk) {
        json += chunk;
    });
    gunzip.on('end', function () {
        if (res.statusCode === 200) {
            try {
                let data = JSON.parse(json);
                console.log('STEEM balance: ' + data.user.balance);
                console.log('SBD balance: ' + data.user.sbd_balance);
                console.log('VEST balance: ' + data.user.vesting_shares);
            } catch (e) {
                console.log('Error parsing JSON');
            }
        } else {
            console.log('Non-200 status code received: ' + res.statusCode);
        }
    }).on('error', function (err) {
        console.log('Error pulling JSON: ' + err);
    });
});

Enjoy and Steem On!

Leave Pulling wallet (and other) profile data from steemit.com/@username.json using javascript to:

Written by

Ex Head of Engineering @ Steemit Inc.

Read more #steemdev posts


Best Posts From Justin Welch

We have not curated any of justinw's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Justin Welch