create account

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

View this thread on: hive.blogpeakd.comecency.com
· @gaottantacinque · (edited)
$15.79
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!
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 38 others
👎  , , , , , , , , , , , ,
properties (23)
authorgaottantacinque
permlinkhere-is-how-you-can-easily-get-a-steemit-account-resource-credit-amount-programmatically
categorysteemit
json_metadata{"tags":["stem","blockchain","neoxian","palnet","programming","javascript","art"],"links":["https://brave.com/myc159","https://api.steemit.com","https://steemit.com/@marcocasario","https://steemit.com/steemit/@gaottantacinque/here-is-how-you-can-easily-get-steemit-accounts-information-programmatically","https://developers.steem.io/apidefinitions/#rc_api.find_rc_accounts"],"app":"steemit/0.1","format":"markdown","image":["https://cdn.steemitimages.com/DQmc5BTWMSBD2LhFGKFKZWcFPhjNeWt9AEykV6FTakkaEhW/image.png"]}
created2020-01-23 09:38:24
last_update2020-01-23 09:53:18
depth0
children6
last_payout2020-01-30 09:38:24
cashout_time1969-12-31 23:59:59
total_payout_value7.487 HBD
curator_payout_value8.307 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,893
author_reputation13,463,378,539,470
root_title"Here is how you can easily get a Steemit account Resource Credit amount programmatically"
beneficiaries
0.
accountsteempeak
weight1,000
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id94,678,825
net_rshares56,494,148,289,705
author_curate_reward""
vote details (115)
@beerlover ·
<div class='pull-right'>https://cdn.steemitimages.com/DQmaHThyECGhEx8tSfHZbiMFRNYjJ35K92cDgiJjkzBUaJo/One%20sip%20of%20BEER%20for%20you.gif<p><sup><a href='https://steem-engine.com/?p=market&t=BEER'>View or trade </a> <code>BEER</code>.</sup></p></div><center><br> <p> Hey @gaottantacinque, here is a little bit of <code>BEER</code> from @eii for you. Enjoy it!</p> <p>Learn how to <a href='https://steemit.com/beer/@beerlover/what-is-proof-of-stake-with-beer'>earn FREE BEER each day </a> by staking.</p> </center><div></div>
properties (22)
authorbeerlover
permlinkre-here-is-how-you-can-easily-get-a-steemit-account-resource-credit-amount-programmatically-20200124t153847z
categorysteemit
json_metadata"{"app": "beem/0.21.1"}"
created2020-01-24 15:38:51
last_update2020-01-24 15:38:51
depth1
children0
last_payout2020-01-31 15:38:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length526
author_reputation25,764,592,104,293
root_title"Here is how you can easily get a Steemit account Resource Credit amount programmatically"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id94,726,575
net_rshares0
@eii ·
!shop
$trdo
!BEER
for you
properties (22)
authoreii
permlinkre-gaottantacinque-q4mbgf
categorysteemit
json_metadata{"tags":["steemit"],"app":"steempeak/2.2.8"}
created2020-01-24 15:38:36
last_update2020-01-24 15:38:36
depth1
children0
last_payout2020-01-31 15:38:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length25
author_reputation181,231,422,780,786
root_title"Here is how you can easily get a Steemit account Resource Credit amount programmatically"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id94,726,569
net_rshares0
@minnowvotes ·
re-gaottantacinque-here-is-how-you-can-easily-get-a-steemit-account-resource-credit-amount-programmatically-20200125t062621986z
You got a 8.01% upvote from @minnowvotes courtesy of @steemium!
properties (22)
authorminnowvotes
permlinkre-gaottantacinque-here-is-how-you-can-easily-get-a-steemit-account-resource-credit-amount-programmatically-20200125t062621986z
categorysteemit
json_metadata{"app":"postpromoter/2.1.1"}
created2020-01-25 06:26:21
last_update2020-01-25 06:26:21
depth1
children0
last_payout2020-02-01 06:26:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length64
author_reputation-125,291,280,752
root_title"Here is how you can easily get a Steemit account Resource Credit amount programmatically"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id94,746,277
net_rshares0
@steemitboard ·
Congratulations @gaottantacinque! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

<table><tr><td><img src="https://steemitimages.com/60x70/http://steemitboard.com/@gaottantacinque/commented.png?202001241904"></td><td>You got more than 400 replies. Your next target is to reach 500 replies.</td></tr>
</table>

<sub>_You can view [your badges on your Steem Board](https://steemitboard.com/@gaottantacinque) and compare to others on the [Steem Ranking](https://steemitboard.com/ranking/index.php?name=gaottantacinque)_</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>



###### [Vote for @Steemitboard as a witness](https://v2.steemconnect.com/sign/account-witness-vote?witness=steemitboard&approve=1) to get one more award and increased upvotes!
properties (22)
authorsteemitboard
permlinksteemitboard-notify-gaottantacinque-20200124t194829000z
categorysteemit
json_metadata{"image":["https://steemitboard.com/img/notify.png"]}
created2020-01-24 19:48:30
last_update2020-01-24 19:48:30
depth1
children0
last_payout2020-01-31 19:48:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length870
author_reputation38,975,615,169,260
root_title"Here is how you can easily get a Steemit account Resource Credit amount programmatically"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id94,735,412
net_rshares0
@steemium ·
steemium-comment-1579933485547
3.27 USD has been spent to promote this content using [Steemium](https://steemium.com/?ref=here-is-how-you-can-easily-get-a-steemit-account-resource-credit-amount-programmatically) . <br> Learn more [here!](https://steemit.com/steem/@steemium/annoucing-steemium-steem-promotion-made-easy-cheap-and-intelligent)
properties (22)
authorsteemium
permlinksteemium-comment-re-gaottantacinque-here-is-how-you-can-easily-get-a-steemit-account-resource-credit-amount-programmatically-20200125t062445547z
categorysteemit
json_metadata{"app":"steemium"}
created2020-01-25 06:24:45
last_update2020-01-25 06:24:45
depth1
children0
last_payout2020-02-01 06:24:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length311
author_reputation14,451,205,037,129
root_title"Here is how you can easily get a Steemit account Resource Credit amount programmatically"
beneficiaries
0.
accountsteemium.vote
weight10,000
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id94,746,249
net_rshares0
@tristancarax ·
[![SBI.png](https://files.steempeak.com/file/steempeak/tristancarax/5xtHrWV9-SBI.png)](https://steempeak.com/@steembasicincome)

You have been supported by members of the SBI community that follow this [new plan of action](https://steempeak.com/sbi/@tristancarax/re-tristancarax-q4a00w). 

Thanks for being a part of this awesome community. Keep on doing what you are doing!
properties (22)
authortristancarax
permlinkre-gaottantacinque-q4qysp
categorysteemit
json_metadata{"tags":["steemit"],"app":"steempeak/2.2.8"}
created2020-01-27 03:53:15
last_update2020-01-27 03:53:15
depth1
children0
last_payout2020-02-03 03:53:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length374
author_reputation53,928,476,951,778
root_title"Here is how you can easily get a Steemit account Resource Credit amount programmatically"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id94,800,326
net_rshares0