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

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@gaottantacinque·
0.000 HBD
Here is how you can easily get a Steemit account Resource Credit amount programmatically
https://cdn.steemitimages.com/DQmc5BTWMSBD2LhFGKFKZWcFPhjNeWt9AEykV6FTakkaEhW/image.png
<center><sub>Screenshot of my script in action in the [Brave browser](https://brave.com/myc159) Console</sub></center>

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:

<code><pre>
var TARGET_ACCOUNT = 'cribbio';

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

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

<pre><code>

-----

<h4>USAGE:</h4>

This is even easier than [retrieving a Steemit account information programmatically](https://steemit.com/steemit/@gaottantacinque/here-is-how-you-can-easily-get-steemit-accounts-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](https://developers.steem.io/apidefinitions/#rc_api.find_rc_accounts)). This means that you can try this simple script in any webpage.

<h5>Step by step instructions:</h5>

<h4>STEP 1</h4>

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

<h4>STEP 2</h4>

Copy and paste my script above in the Console.

<h4>STEP 3</h4>

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!
👍 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,