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

avatar
(Edited)


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!



0
0
0.000
6 comments
avatar

!shop
$trdo
!BEER
for you

0
0
0.000
avatar

Congratulations @gaottantacinque! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You got more than 400 replies. Your next target is to reach 500 replies.

You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Vote for @Steemitboard as a witness to get one more award and increased upvotes!
0
0
0.000
avatar

SBI.png

You have been supported by members of the SBI community that follow this new plan of action.

Thanks for being a part of this awesome community. Keep on doing what you are doing!

0
0
0.000