Part 5 of this series discusses how to query Resource Credits (RC) account balance and how to check current RC costs for various Hive blockchain operations. The examples here require some knowledge from parts 1 - 3. If youโre new to coding on Hive with Python, itโs strongly recommended to review [the earlier posts](https://peakd.com/@learncode) first.  --- ## Background - How does the Resource Credits (RC) System Work Hive has a really interesting system called Resource Credits. Different operations have a cost, and the costs adjust dynamically based on network utilization. Every wallet has a pool of resource credits that can be spent on operations. The maximum number of RCs in the pool is determined by the amount of Hive Power. And the RC pool gradually replenishes over time. Voting on a post uses a tiny amount of RCs. Claiming an account creation token costs a huge amount of RCs. Wallets with around 5,000 HP can claim one account creation token roughly every 3 days. The cost is variable! Larger stakeholders benefit from waiting for lower RC costs for opportunities to claim lower-cost tokens. Using **Python** and the **beem** library, itโs easy to check for the RC cost for various Hive operations. For this purpose, beem has a convenient `RC()` object. The code snippets below demonstrate how. ## Step 1 - Checking RC Costs of Various Hive Operations In step 1, **beem** is called upon to check RC costs of 4 types of operations. First, we need to `import beem` and set up a Hive blockchain object. Then, feed it in to instantiate beem's RC object `beem.rc.RC()`. The RC object has convenient methods for requesting the current RC costs of various operation types: custom_json, vote, comment (same as post), and account creation token claims (claim_account). Calling those returns the RC cost as an integer. Last, `print()` out the results. Code snippet: ``` import beem hive = beem.Hive() rc = beem.rc.RC(hive_instance=hive) comment_cost = rc.comment() vote_cost = rc.vote() json_cost = rc.custom_json() account_cost = rc.claim_account() print('Current RC costs => Custom_json: %d | Vote: %d | Comment/Post: %d | Account Creation Token: %d' % (json_cost, vote_cost, comment_cost, account_cost)) ``` Expected output: ``` Current RC costs => Custom_json: 157471719 | Vote: 103030502 | Comment/Post: 1129593147 | Account Creation Token: 6391759705103 ``` --- ## Step 2 - Checking the Current RC Balance of a Hive Account In step 2, **beem** is called upon to check the current RC balance for a Hive wallet. Beem refers to RC balance as *mana*. Like in LearnCode#3, the `input()` function prompts the user for keyboard input, asking the Hive wallet name. The specified name is passed to beem's `Account()` object instantiation. Then, the Account object's `get_rc_manabar()` method is called to get the current RC balance. The response is a dictionary with several keys including the maximum RC count and the time to fully recharge, but for now all that's needed is the `'current_mana'` value. Last, print out a nice message including wallet name and the current RC count. Code snippet: ``` import beem ACCOUNT_NAME = input('Enter account name: ') acc = beem.account.Account(ACCOUNT_NAME) mana = acc.get_rc_manabar()['current_mana'] print('Current mana for @%s is %d RCs' % (ACCOUNT_NAME, mana)) ``` Expected output: ``` Enter account name: learncode Current mana for @learncode is 9314719867 RCs ``` ## Putting it All Together - Determining How Many Ops Are Possible for the Account Combining snippets from step 1 and step 2, we can calculate, for a given account, how many votes, comments, etc can be broadcast with the current RC balance. First, use code from step 1 to get the current RC costs of the four operation types. Then, query the account's current RC balance. Then compute the number of possible operations of each type. Finally, print out the numbers for each operation. Code snippet: ``` import beem hive = beem.Hive() rc = beem.rc.RC(hive_instance=hive) ACCOUNT_NAME = input('Enter account name: ') comment_cost = rc.comment() vote_cost = rc.vote() json_cost = rc.custom_json() account_cost = rc.claim_account() print('Current RC costs => Custom_json: %d | Vote: %d | Comment/Post: %d | Account Creation Token: %d' % (json_cost, vote_cost, comment_cost, account_cost)) acc = beem.account.Account(ACCOUNT_NAME) mana = acc.get_rc_manabar()['current_mana'] possible_jsons = int(mana / json_cost) possible_votes = int(mana / vote_cost) possible_comments = int(mana / comment_cost) possible_accounts = int(mana / account_cost) print('Account %s can make %d jsons, %d votes, %d comments, %d accounts' % (ACCOUNT_NAME, possible_jsons, possible_votes, possible_comments, possible_accounts)) ``` Expected Output: ``` Enter account name: learncode Current RC costs => Custom_json: 157474527 | Vote: 103032095 | Comment/Post: 1129608754 | Account Creation Token: 6391034357264 Account learncode can make 59 jsons, 90 votes, 8 comments, 0 accounts ```  p.s. Thanks for reading. Please let me know if anything is unclear or incorrect. This is intended to be a living document to be improved and maintained over time. --- This blog is produced by the @Hive.Pizza team (@hivetrending and @thebeardflex). PIZZA Crew is a Hive-powered social group empowering content creators, gamers, and YOU. We host game servers, a DLUX node, a Hive-Engine node, and now a Hive witness node! Please help us out and give your [vote](https://vote.hive.uno/@pizza.witness) of approval for our witness (@pizza.witness). Here's a convenient way to [vote](https://vote.hive.uno/@pizza.witness) using HiveKeychain or HiveSigner: https://vote.hive.uno/@pizza.witness. Thanks for your support!
author | learncode |
---|---|
permlink | part-5-coding-on-hive-with-python-working-with-resource-credits |
category | programming |
json_metadata | "{"app":"peakd/2021.07.1","format":"markdown","description":"Part 5 discusses how to query Resource Credits (RC) account balance and how to check RC costs for various Hive ops","tags":["programming","coding","hive","python","beem","ctp","palnet","proofofbrain","stem","broadhive"],"users":["learncode","Hive.Pizza","hivetrending","thebeardflex","pizza.witness","pizza.witness."],"image":["https://files.peakd.com/file/peakd-hive/learncode/23u6X11XGuTsKsvrFZBDpA6McV75Cktey1qgw7R1239yHaFSP6bHNh5reE5qZQaGMXVVC.png","https://files.peakd.com/file/peakd-hive/learncode/23u5ZX2czd4dwvPTAxnpNvXoYYWUL23xvbe8hF6Kts2Qnc6598MEYjZuSEG8bCR159T3N.png"]}" |
created | 2021-07-05 20:38:06 |
last_update | 2021-07-05 20:38:06 |
depth | 0 |
children | 7 |
last_payout | 2021-07-12 20:38:06 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 1.202 HBD |
curator_payout_value | 1.191 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 5,995 |
author_reputation | 682,726,195,093 |
root_title | "Part 5: Coding on Hive With Python - Working with Resource Credits" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 104,742,033 |
net_rshares | 4,756,321,997,270 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
arcange | 0 | 108,732,885,312 | 2% | ||
raphaelle | 0 | 533,554,631 | 1% | ||
steevc | 0 | 676,993,820,767 | 41% | ||
zorg67 | 0 | 610,927,876 | 100% | ||
edb | 0 | 31,211,885,288 | 20.5% | ||
walterjay | 0 | 3,556,534,160 | 0.35% | ||
enjar | 0 | 705,459,199,123 | 100% | ||
tipy | 0 | 0 | 100% | ||
felt.buzz | 0 | 3,020,553,993 | 0.35% | ||
anadolu | 0 | 181,075,732,273 | 25% | ||
mytechtrail | 0 | 52,087,623,145 | 15% | ||
fourfourfun | 0 | 7,559,811,181 | 25% | ||
joebrochin | 0 | 101,471,079,284 | 60% | ||
markoslaw | 0 | 2,497,566,880 | 100% | ||
manniman | 0 | 51,179,502,894 | 11% | ||
tonimontana | 0 | 7,845,230,218 | 100% | ||
beco132 | 0 | 1,470,342,952 | 78.98% | ||
bilimkurgu | 0 | 7,809,990,817 | 25% | ||
yintercept | 0 | 163,464,729,755 | 100% | ||
dalz | 0 | 585,820,408,778 | 98% | ||
holovision | 0 | 102,029,799,699 | 100% | ||
luppers | 0 | 721,837,132 | 1% | ||
bengiles | 0 | 802,387,270,094 | 100% | ||
pboulet | 0 | 696,482,065 | 0.7% | ||
cliffagreen | 0 | 5,957,453,963 | 50.3% | ||
charitycurator | 0 | 3,347,573,019 | 10% | ||
ctime | 0 | 170,297,854,453 | 2.5% | ||
vagabondspirit | 0 | 5,665,613,767 | 100% | ||
limka | 0 | 202,703,120 | 82.06% | ||
thelogicaldude | 0 | 94,569,458,678 | 60% | ||
stemgeeks | 0 | 65,130,211,710 | 60% | ||
stemcuration | 0 | 2,109,436,324 | 60% | ||
babytarazkp | 0 | 2,832,865,221 | 40% | ||
abh12345.stem | 0 | 3,032,540,218 | 100% | ||
stem.alfa | 0 | 92,783,165 | 100% | ||
yggdrasil.laguna | 0 | 128,962,924 | 30% | ||
oblivioncubed | 0 | 147,174,367,288 | 50% | ||
chapmain | 0 | 126,360,348 | 100% | ||
lacking | 0 | 197,819,707,332 | 100% | ||
stuntman.mike | 0 | 3,935,277,380 | 100% | ||
fengchao | 0 | 2,789,248,963 | 1% | ||
hivetrending | 0 | 26,141,502,097 | 50% | ||
laruche | 0 | 27,938,015,350 | 0.7% | ||
heystack | 0 | 1,613,411,637 | 100% | ||
localgrower | 0 | 1,085,667,652 | 10% | ||
thatcryptodave | 0 | 66,819,169,654 | 67% | ||
stickupboys | 0 | 30,049,261,391 | 52% | ||
cryptonian007 | 0 | 39,385,766 | 25% | ||
focus.folks | 0 | 0 | 100% | ||
pfwaus | 0 | 1,306,184,813 | 100% | ||
abdul.qadir | 0 | 0 | 0.62% | ||
dorkpower | 0 | 2,933,678,849 | 100% | ||
aiovo | 0 | 515,579,695 | 4.2% | ||
stemcur | 0 | 1,074,124,986 | 100% | ||
brofund-stem | 0 | 819,767,051 | 30% | ||
rikarivka | 0 | 4,997,311,097 | 100% | ||
nathen007.stem | 0 | 163,319,973 | 100% | ||
stemline | 0 | 3,487,362,557 | 30% | ||
meestemboom | 0 | 978,416,120 | 50% | ||
emrebeyler.stem | 0 | 1,486,499,093 | 100% | ||
scientician | 0 | 89,501,058 | 100% | ||
scooter77.stem | 0 | 621,938,707 | 60% | ||
dadspardan | 0 | 12,552,137,099 | 50% | ||
krishu.stem | 0 | 866,285,931 | 100% | ||
dannychain | 0 | 2,074,533,546 | 50% | ||
adamada.stem | 0 | 1,102,016,439 | 100% | ||
huzzah | 0 | 18,470,295,727 | 100% | ||
cooperclub | 0 | 39,531,273,146 | 50% | ||
nyxlabs | 0 | 3,355,083,962 | 50% | ||
creodas | 0 | 881,714,869 | 75% | ||
horstman5 | 0 | 1,084,581,556 | 50% | ||
hive.pizza | 0 | 174,811,289,886 | 100% | ||
juecoree.stem | 0 | 566,211,054 | 100% | ||
trippymane | 0 | 8,996,262,723 | 100% | ||
chireerocks.bht | 0 | 128,538,000 | 100% | ||
pizzabot | 0 | 9,583,982,245 | 100% | ||
holovision.stem | 0 | 0 | 50% | ||
faireye.bht | 0 | 1,079,492,303 | 100% | ||
dibblers.dabs | 0 | 3,806,710,417 | 50% | ||
star.stem | 0 | 1,822,304,631 | 50% | ||
firefist91 | 0 | 0 | 100% |
Congratulations @learncode! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) : <table><tr><td><img src="https://images.hive.blog/60x70/http://hivebuzz.me/@learncode/replies.png?202107052146"></td><td>You got more than 50 replies.<br>Your next target is to reach 100 replies.</td></tr> </table> <sub>_You can view your badges on [your board](https://hivebuzz.me/@learncode) and compare yourself to others in the [Ranking](https://hivebuzz.me/ranking)_</sub> <sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub> **Check out the last post from @hivebuzz:** <table><tr><td><a href="/hivebuzz/@hivebuzz/pud-202107-feedback"><img src="https://images.hive.blog/64x128/https://i.imgur.com/zHjYI1k.jpg"></a></td><td><a href="/hivebuzz/@hivebuzz/pud-202107-feedback">Feedback from the July 1st Hive Power Up Day - ATH Volume record!</a></td></tr></table>
author | hivebuzz |
---|---|
permlink | hivebuzz-notify-learncode-20210705t221147000z |
category | programming |
json_metadata | {"image":["http://hivebuzz.me/notify.t6.png"]} |
created | 2021-07-05 22:11:48 |
last_update | 2021-07-05 22:11:48 |
depth | 1 |
children | 0 |
last_payout | 2021-07-12 22:11:48 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 960 |
author_reputation | 369,386,340,709,685 |
root_title | "Part 5: Coding on Hive With Python - Working with Resource Credits" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 104,743,301 |
net_rshares | 0 |
<div class='pull-right'><center><sup>Connect</sup></center><p><a href="https://discord.gg/Q9bQAKpWGS"><img src="https://files.peakd.com/file/peakd-hive/pizzabot/AKF96fKjnX3wjXERHcKAFHaoHnfTVhXqPjXVz8E1Th9nPiJqmFtaycosVpPBZ7z.png"></a></p></div><div class='pull-right'><center><sup>Trade</sup></center><p><a href='https://hive-engine.com/?p=market&t=PIZZA'><img src="https://files.peakd.com/file/peakd-hive/pizzabot/23sxbi2M4UjELDzQjxPdzubdgfMjHTCtA1xueyxmnhJUrB8136VyK3pqynyWYiZYF9HrC.png"></a></p></div><center><br> <p>@learncode! This post has been manually curated by the <strong><em>$PIZZA</em></strong> Token team!</p><p>Learn more about <strong><em>$PIZZA Token</em></strong> at <a href="https://hive.pizza">hive.pizza</a>. Enjoy a slice of $PIZZA on us!</p> </center><div></div>
author | pizzabot |
---|---|
permlink | re-part-5-coding-on-hive-with-python-working-with-resource-credits-20210705t234640z |
category | programming |
json_metadata | "{"app": "beem/0.24.26"}" |
created | 2021-07-05 23:46:42 |
last_update | 2021-07-05 23:46:42 |
depth | 1 |
children | 0 |
last_payout | 2021-07-12 23:46:42 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 785 |
author_reputation | 7,561,320,422,270 |
root_title | "Part 5: Coding on Hive With Python - Working with Resource Credits" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 104,744,535 |
net_rshares | 0 |
https://twitter.com/HiveTrending/status/1412149263027490822 <sub> The rewards earned on this comment will go directly to the person sharing the post on Twitter as long as they are registered with @poshtoken. </sub>
author | poshtoken | ||||||
---|---|---|---|---|---|---|---|
permlink | re-learncode-part-5-coding-on-hive-with-python-working-with-res20875 | ||||||
category | programming | ||||||
json_metadata | "{"app":"Poshtoken 0.0.1"}" | ||||||
created | 2021-07-05 20:40:18 | ||||||
last_update | 2021-07-05 20:40:18 | ||||||
depth | 1 | ||||||
children | 0 | ||||||
last_payout | 2021-07-12 20:40:18 | ||||||
cashout_time | 1969-12-31 23:59:59 | ||||||
total_payout_value | 0.000 HBD | ||||||
curator_payout_value | 0.000 HBD | ||||||
pending_payout_value | 0.000 HBD | ||||||
promoted | 0.000 HBD | ||||||
body_length | 215 | ||||||
author_reputation | 5,413,052,484,832,097 | ||||||
root_title | "Part 5: Coding on Hive With Python - Working with Resource Credits" | ||||||
beneficiaries |
| ||||||
max_accepted_payout | 1,000,000.000 HBD | ||||||
percent_hbd | 0 | ||||||
post_id | 104,742,068 | ||||||
net_rshares | 0 |
lol i always look at these posts.....then check my glasses....then realise I dont speak spanish... can you google translate this? !PIZZA 
author | stickupboys |
---|---|
permlink | re-learncode-qvsneo |
category | programming |
json_metadata | {"tags":["programming"],"app":"peakd/2021.07.1"} |
created | 2021-07-05 22:49:36 |
last_update | 2021-07-05 22:49:36 |
depth | 1 |
children | 1 |
last_payout | 2021-07-12 22:49:36 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 227 |
author_reputation | 488,834,890,932,513 |
root_title | "Part 5: Coding on Hive With Python - Working with Resource Credits" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 104,743,745 |
net_rshares | 0 |
<div class='pull-right'><center><sup>Connect</sup></center><p><a href="https://discord.gg/Q9bQAKpWGS"><img src="https://files.peakd.com/file/peakd-hive/pizzabot/AKF96fKjnX3wjXERHcKAFHaoHnfTVhXqPjXVz8E1Th9nPiJqmFtaycosVpPBZ7z.png"></a></p></div><div class='pull-right'><center><sup>Trade</sup></center><p><a href='https://hive-engine.com/?p=market&t=PIZZA'><img src="https://files.peakd.com/file/peakd-hive/pizzabot/23sxbi2M4UjELDzQjxPdzubdgfMjHTCtA1xueyxmnhJUrB8136VyK3pqynyWYiZYF9HrC.png"></a></p></div><center><br> <p>@learncode! I sent you a slice of <strong><em>$PIZZA</em></strong> on behalf of @stickupboys.</p> <p>Learn more about <strong><em>$PIZZA Token</em></strong> at <a href="https://hive.pizza">hive.pizza</a> <sub>(7/20)</sub></p> </center><div></div>
author | pizzabot |
---|---|
permlink | re-re-learncode-qvsneo-20210705t225041z |
category | programming |
json_metadata | "{"app": "beem/0.24.26"}" |
created | 2021-07-05 22:50:42 |
last_update | 2021-07-05 22:50:42 |
depth | 2 |
children | 0 |
last_payout | 2021-07-12 22:50:42 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 766 |
author_reputation | 7,561,320,422,270 |
root_title | "Part 5: Coding on Hive With Python - Working with Resource Credits" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 104,743,756 |
net_rshares | 0 |
This is great content for any #hivehustlers wanting to mess around with Python!
author | thelogicaldude |
---|---|
permlink | re-learncode-qvtnvl |
category | programming |
json_metadata | {"tags":["programming"],"app":"peakd/2021.07.1"} |
created | 2021-07-06 11:57:21 |
last_update | 2021-07-06 11:57:21 |
depth | 1 |
children | 1 |
last_payout | 2021-07-13 11:57:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.047 HBD |
curator_payout_value | 0.047 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 80 |
author_reputation | 360,705,107,758,635 |
root_title | "Part 5: Coding on Hive With Python - Working with Resource Credits" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 104,752,989 |
net_rshares | 187,111,356,172 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
yintercept | 0 | 160,400,693,833 | 100% | ||
vagabondspirit | 0 | 5,557,756,488 | 100% | ||
stemgeeks | 0 | 20,512,198,702 | 20% | ||
stemcuration | 0 | 631,416,181 | 20% | ||
yggdrasil.laguna | 0 | 9,290,968 | 10% |
Thanks for reading!
author | learncode |
---|---|
permlink | re-thelogicaldude-202176t6325654z |
category | programming |
json_metadata | {"tags":["programming"],"app":"ecency/3.0.18-mobile","format":"markdown+html"} |
created | 2021-07-06 13:32:06 |
last_update | 2021-07-06 13:32:06 |
depth | 2 |
children | 0 |
last_payout | 2021-07-13 13:32:06 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.015 HBD |
curator_payout_value | 0.015 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 19 |
author_reputation | 682,726,195,093 |
root_title | "Part 5: Coding on Hive With Python - Working with Resource Credits" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 104,754,338 |
net_rshares | 61,693,174,701 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
thelogicaldude | 0 | 61,693,174,701 | 40% |