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.30
TRX 0.12
JST 0.033
BTC 63672.27
ETH 3126.79
USDT 1.00
SBD 3.87