How to use the Steem API, For Beginners

inertia(74)
Published in
#howto
Words
618
Reading
3 min
Listen
Play
8y

You don't need to use a programming language to access the blockchain. You can use terminal commands or other tools like Rested to create a POST request.

If you have no experience accessing the Steem API, let's go over some basics so you'll be empowered to do great things.

Rested

You can use the Rested Chrome Extension to access the blockchain.

After installing this extension, click on the </> icon, switch to POST and type in the API endpoint:

Then set the type to Custom and paste the example jsonrpc request:

The rest of this tutorial assumes you're passing the jsonrpc request using curl from the terminal.

Terminal

To use this tutorial, we need to access the terminal. Accessing the terminal is outside the scope of this article, but some helpful Google search phrases would be:

how to access the terminal on windows

curl

The command we're going to use is called curl. It's short for "command line url". Its purpose is to access a web resource pretty much just like a browser, then return the contents of the resource as text.

Installing curl is also outside the scope of this article. Many operating systems already provide curl, but some do not. Some can install it with their package manager.

how to install curl on windows

Something Simple: get_account_count

First, let's make our goal simple. We want to know how many accounts there are on the platform. Lucky for us, there's a single API method specifically for doing this, and the method is called condenser_api.get_account_count.

curl -s --data \
'{
  "jsonrpc":"2.0",
  "id":1,
  "method":"condenser_api.get_account_count",
  "params":[]
}' \
https://api.steemit.com

Now, let's go over this command.

  • curl - The actual command we're running locally.
  • -s - Means be silent, don't show statistics of the command. If we leave this off, we'll get some extra data about the request/response cycle of curl, but it's a distraction here.
  • --data - Tells curl we are making a POST request followed by the body of the post in '' single quotes.
    • POST request body, which is passed by curl to the remote host:
      • "jsonrpc" - Tells the remote host we intend to follow the jsonrpc spec: "2.0"
      • "method" - The full name of the method, in this case "condenser_api.get_account_count"
      • "params" - The required parameters of this method, in this case none.
      • "id" - The jsonrpc id that will be repeated to us in the response.

Here's the response, look at the result value.

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": 1023875
}

The response we get is broken down into the following fields:

  • "id" - The jsonrpc id repeated, in this case, we passed 1 in the request, so we got 1 in the response.
  • "jsonrpc" - Since we asked for "2.0", we got the same in the response.
  • "result" - The actual result of the method. At the time of writing, there are 1,023,875 accounts.

Something Slightly Complicated: get_active_votes

The method we're going to try here requires two parameters. When we call condenser_api.get_active_votes, it needs to know which author and permlink we're interested in.

We're going to do the query on my very first post: That's Nutrition!

curl -s --data \
'{
  "jsonrpc":"2.0",
  "id":1,
  "method":"condenser_api.get_active_votes",
  "params":["inertia", "that-s-nutrition"],
}' \
https://api.steemit.com

Like before, we have "jsonrpc", "id", and "method". But unlike before, we're not passing an empty "params" array. Instead, we're passing ["inertia", "that-s-nutrition"] to identify the exact post we're interested in.

{
   "jsonrpc":"2.0",
   "result":[
      {
         "voter":"zebbra2014",
         "weight":"5578646898886369",
         "rshares":1210323275,
         "percent":10000,
         "reputation":-2683223274535,
         "time":"2016-07-14T01:36:42"
      },
      {
         "voter":"riscadox",
         "weight":"400782100556392",
         "rshares":86924063,
         "percent":10000,
         "reputation":"5488837804926",
         "time":"2016-07-13T07:34:09"
      },
      {
         "voter":"warplat",
         "weight":"321958340660123",
         "rshares":69873283,
         "percent":10000,
         "reputation":"327774469729",
         "time":"2016-07-14T02:01:00"
      },
      {
         "voter":"gjhi4552201",
         "weight":0,
         "rshares":52219629,
         "percent":10000,
         "reputation":3798781589,
         "time":"2016-07-13T07:43:33"
      },
      {
         "voter":"qwertas",
         "weight":"68245735399657",
         "rshares":75902299,
         "percent":10000,
         "reputation":-279089549224,
         "time":"2016-07-13T07:08:48"
      },
      {
         "voter":"inertia",
         "weight":0,
         "rshares":240003499,
         "percent":10000,
         "reputation":"126460782517772",
         "time":"2016-07-13T07:02:57"
      },
      {
         "voter":"seb",
         "weight":0,
         "rshares":110951939,
         "percent":10000,
         "reputation":"1192866377126",
         "time":"2016-07-14T22:12:09"
      }
   ],
   "id":1
}

Here, you can see every voter and all of the details that go into their vote. Compare this result to:

https://steemd.com/funny/@inertia/that-s-nutrition

  • voter - The person who cast a vote.
  • weight - The score this vote receives, used by vote payout calculation. Note: Becomes 0 if a negative vote or changed votes.
  • rshares - Shares the voter received as a curation reward.
  • percent - The integer version of the vote (10000 / 100 = 100.00 %)
  • reputation - The reputation of the voter now, not when the vote was cast.
  • time - When the vote was cast.





ACCESS LIMITS: Clients may maintain connections to the server for no more than 86,400 seconds per day. If you need additional time, you may contact IERS to file a request for up to one additional second.

How to use the Steem API, For Beginners | Ecency