2 minute quick start - steem.ws API

By @aglo8/10/2016steem-help

![steemws-aglob65ee.md.gif](https://www.steemimg.com/images/2016/08/10/steemws-aglob65ee.md.gif)

If anyone missed the trending page yesterday, @xeroc and @jesta released an api cluster (https://steem.ws) that allows us to connect directly to steem via websocket. I've found this tool incredibly useful for ad hoc analytics and wanted to share a quick guide to help folks get up and running.

This example utilizes the steem.ws websocket to display steem user data in the browser. Working sample also available here

Quick Start

Install dependencies if needed

sudo npm install serve -g

Grab the repo and serve

git clone https://github.com/gloneka/steem-ws-quickstart.git

cd steem-ws-quickstart

serve --port 3000

You should now be able to access the tool here: http://localhost:3000. Just enter a user name in the input box to see the corresponding steem data.

Websocket Setup

socket.js

var socket = new WebSocket('wss://node.steem.ws')

socket.onmessage = function(res, flags) {
    //res.data contains results
}

Steem API Format

{"jsonrpc": "2.0", "params": [], "id": 1, "method": ""}

This structure varies a bit between calls, so I've included a few additional examples below. I would also recommend checking out @xeroc's post: Steem API from a few months ago.

//user info
socket.send('{"jsonrpc": "2.0", "params": [["aglo"]], "id": 1, "method": "get_accounts"}')

// # of registered accounts
socket.send('{"jsonrpc": "2.0", "params": ["database_api", "get_account_count", [1]], "id": 1 "method": "call"}');

//trending categories
socket.send('{"jsonrpc": "2.0", "params": ["database_api", "get_trending_categories", ["",50]], "id": 1 "method": "call"}');

//order book
socket.send('{"jsonrpc": "2.0", "params": ["database_api", "get_order_book", [100]], "id": 1 "method": "call"}');

Thanks for reading! I hope you found this helpful.

7

comments