Here is how you can easily get a Steemit account Resource Credit amount programmatically


Screenshot of my script in action in the Brave browser Console

Tonight I read someone in a Discord channel wondering how we can programmatically read a user's RC.

I could not find any documentation online, so I start researching which websites currently display a RC bar.

After investigating some of their network calls without success, I started looking at their minified code and found something that seemed doing what I was looking for.

After prettifying it with an online tool and digging a bit more into it I figure it out.

So here it is in case you need it as well:


var TARGET_ACCOUNT = 'cribbio';

var getResourceCredits = (user) => new Promise((resolve) => {
  fetch('https://api.steemit.com', {
    credentials: 'omit',
    headers: {
      accept: 'application/json',
      'accept-language': 'en-US,en;q=0.9',
      'cache-control': 'max-age=0',
      'content-type': 'application/json;charset=UTF-8',
      'sec-fetch-mode': 'cors',
      'sec-fetch-site': 'cross-site',
    },
    referrer: 'https://steemit.com/@marcocasario',
    referrerPolicy: 'no-referrer-when-downgrade',
    body: JSON.stringify({
      id: '1',
      jsonrpc: '2.0',
      method: 'rc_api.find_rc_accounts',
      params: {'accounts': [user]},
    }),
    method: 'POST',
    mode: 'cors',
  })
  .then(res => res.json())
  .then(({ result } = {}) => {
    const { rc_manabar, max_rc } = result.rc_accounts[0];
    const time = Math.round((new Date).getTime() / 1e3) - rc_manabar.last_update_time;
    const maxMana = parseInt(max_rc);
    const currentMana = parseInt(rc_manabar.current_mana) + Math.round(maxMana / 432e3 * time);
    const percentage = Math.min(currentMana / maxMana * 100, 100);
    resolve(percentage);
  });
});

getResourceCredits(TARGET_ACCOUNT)
  .then((result) => console.log(TARGET_ACCOUNT, 'is at', result, '% of their RC.'));



USAGE:

This is even easier than retrieving a Steemit account information programmatically as there is no need to import SteemJs or SteemdJs.

It simply uses a cross domain http requests (see documentation on developers.steem.io). This means that you can try this simple script in any webpage.

Step by step instructions:

STEP 1

Open your favorite browser on any site (I strongly recommend to use Brave browser, by the way)
and open the DevTools (Ctrl + Shift + J on Linux/Windows and Cmd + Opt + J on Mac).

STEP 2

Copy and paste my script above in the Console.

STEP 3

Press enter and there you go! You can now see a console log telling you the percentage of RC still available to the target user.

If you want to retry with a different user simply paste the script again, change the top variable and press enter again.

Enjoy!! =]

NOTE:
As usual, this script is completely safe as it does not require any sort of keys to function!

H2
H3
H4
Upload from PC
Video gallery
3 columns
2 columns
1 column
6 Comments