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

in #steemdev7 years ago

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!

Sort:  

Cool. Thanks

Coin Marketplace

STEEM 0.20
TRX 0.20
JST 0.034
BTC 89846.05
ETH 3077.33
USDT 1.00
SBD 2.96