Steem API

in #undefined9 years ago

This article desribes the API of the STEEM full node (not of the wallet API).

Prerequisits

This article assumes that you have a full node running and listening to port 8092, locally. You can achieve this by

./programs/steemd/steemd --rpc-endpoint=127.0.0.1:8092

We open up the RPC endpoint so that we can interface with the node using RPC-JSON calls.

Call Format

In Graphene, RPC calls are state-less and accessible via regular JSON formated RPC-HTTP-calls. The correct structure of the JSON call is

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

The get_accounts call is available in the full node's API and takes only one argument which is an array of account ids (here: ["xeroc", "steemit"]).

Example Call with curl

Such as call can be submitted via curl:

curl --data '{"jsonrpc": "2.0", "method": "get_accounts", "params": [["xeroc","steemit"]], "id": 1}' http://127.0.0.1:8090/rpc

Successful Calls

The API will return a properly JSON formated response carrying the same id
as the request to distinguish subsequent calls.

{ "id":1, "result": "data" }

Errors

In case of an error, the resulting answer will carry an error attribute and
a detailed description:

{
  "id": 0
  "error": {
    "data": {
      "code": error-code,
      "name": " .. name of exception .."
      "message": " .. message of exception ..",
      "stack": [ .. stack trace .. ],
    },
    "code": 1,
  },
}

Available Calls

Even though, the help call does not exist, it gives us an error message that contains all available API calls in the stack trace:

curl --data '{"jsonrpc": "2.0", "method": "help", "params": [], "id": 1}' http://127.0.0.1:8090/rpc
{
  "id": 1,
  "error": {
    "message": <...>,
    "data": {
      "message": "Assert Exception",
      "name": "assert_exception",
      "stack": [
        {
          "data": {
            "name": "help",
            "api": {
              "set_subscribe_callback": 0,
              "get_dynamic_global_properties": 12,
              "get_accounts": 17,
              "get_active_categories": 9,
              "get_account_references": 18,
              "get_trending_categories": 7,
              "get_content": 36,
              "get_state": 6,
              "get_discussions_by_total_pending_payout": 38,
              "cancel_all_subscriptions": 3,
              "get_block_header": 4,
              "get_active_votes": 35,
              "get_current_median_history_price": 15,
              "lookup_witness_accounts": 26,
              "verify_account_authority": 34,
              "get_key_references": 16,
              "set_pending_transaction_callback": 1,
              "get_required_signatures": 31,
              "get_recent_categories": 10,
              "get_order_book": 28,
              "lookup_accounts": 20,
              "get_account_history": 23,
              "get_chain_properties": 13,
              "get_feed_history": 14,
              "verify_authority": 33,
              "get_discussions_by_last_update": 40,
              "get_conversion_requests": 22,
              "get_discussions_in_category_by_last_update": 41,
              "get_block": 5,
              "get_witness_count": 27,
              "get_best_categories": 8,
              "get_potential_signatures": 32,
              "lookup_account_names": 19,
              "get_transaction": 30,
              "get_witnesses": 24,
              "get_witness_by_account": 25,
              "get_account_count": 21,
              "get_transaction_hex": 29,
              "get_content_replies": 37,
              "get_discussions_in_category_by_total_pending_payout": 39,
              "get_miner_queue": 43,
              "get_active_witnesses": 42,
              "set_block_applied_callback": 2,
              "get_config": 11
            }
          },
          "context": {
            "line": 109,
            "hostname": "",
            "timestamp": "2016-04-13T16:15:17",
            "method": "call",
            "thread_name": "th_a",
            "level": "error",
            "file": "api_connection.hpp"
          },
          "format": "itr != _by_name.end(): no method with name '${name}'"
        }
      ],
      "code": 10
    },
    "code": 1
  }
}

Further documentation about the calls can be found in the sources in libraries/app/include/steemit/app/database_api.hpp.

Sort:  

@xeroc Hallo, thanks a lot for the post! I'm pretty new to Steemit and Python coding, but I have managed to successfully run some API's off other websites in the past. At the start, where you say "./programs/steemd/steemd --rpc-endpoint=127.0.0.1:8092" can be used to open a RPC endpoint. Do I run that in my CMD? I'm pretty lost. All I basically want is to run script in python, to just print a live list of the activity on the Steemit block chain. Something very similar to http://steemstream.com/ but only in my python window. Please help!

probably need to get each block as it comes in and display what each block has:

curl http://127.0.0.1:8090": "2.0", "method": "call", "params": ["database_api", "get_block", [10000]], "id": 3}'
returns:
{"id":3,"result":{"previous":"0000270f17162d089d8cbf634b7ce434df782c9c","timestamp":"2016-03-25T00:34:48","witness":"itsascam","transaction_merkle_root":"340b3605652c91cd41456656c1915a7b5b46dffa","extensions":[],"witness_signature":"20546ff92d26a7d3ba3e3331a95c6389c9018620f9430fdee8857e925bf7fa13806dbadd7371a244706ba3df0e1ffb0db084aa4019950594d6289a11f4256b66b8","transactions":[{"ref_block_num":9999,"ref_block_prefix":137172503,"expiration":"2016-03-25T01:34:45","operations":[["pow",{"worker_account":"steemit59","block_id":"0000270f17162d089d8cbf634b7ce434df782c9c","nonce":"2069557240858032527","work":{"worker":"STM65wH1LZ7BfSHcK69SShnqCAH5xdoSZpGkUjmzHJ5GCuxEK9V5G","input":"1125c3ab09a55396c55ed60283cd6634d455d7bc1b9efb169952c654923e9f7e","signature":"20194bba7b31c53f7bc74efd9d0524e71ae87e4b60072313d866dac4c722c30da8365c3c28c972f8b06892cf1c60703d4abf550c24f66098e57a7f9671b41caf42","work":"0000000435a0bfad8471034a209d7556b4c16d77b22a66970de224f6fedad95a"},"props":{"account_creation_fee":"100.000 STEEM","maximum_block_size":131072,"sbd_interest_rate":1000}}]],"extensions":[],"signatures":[]}]}}

So you would need a loop that checks for the latest blocknumber and then iterate until you reach that number, then for each block call a parsing function, extracting the info you want to display

Danke @marcelhattingh, dein Tipp 127 wurde notiert, viel Glück!

"method": "get_account" should be "method": "get_accounts" ... thanks for the post!

thanks for the post, would you happen to have any ideas on how i can programatically post to steemit with an API?

Hi @xeroc,

Great post!

I'm looking for an API that allows me to create content (POSTs). I have been reading the documentation and it seems that we can only retrieve information or just create a comments or up-vote.

I wonder if you could point me to some API that allows creating POST in steemit.com.

Thanks,

@realskilled

Coin Marketplace

STEEM 0.21
TRX 0.20
JST 0.034
BTC 98431.01
ETH 3374.12
USDT 1.00
SBD 3.04