I wanted to create a little script to automate the reward claiming for my account. I know there is the amazing hive.autoclaim service, but I wanted to learn a bit more how Hive was working and thought it would be an easy task to begin with. I couldn’t be more wrong. First thing first, I visited the hive developer [documentation](https://developers.hive.io/tutorials). It looks like there is 3 supported languages, javascript, python and ruby so I decided to pick Ruby which is the one I most familiar with.  There is no examples in the tutorial section for claiming rewards with Ruby but the Javascript library has an [example](https://developers.hive.io/tutorials-javascript/claim_rewards.html). So I need two operations, the first one `get_accounts` to have the actual rewards and the second one is `claim_reward_balance`, to make the claim itself. Let’s look at Radiator source code now! ```bash EDITOR=code bundle open radiator ``` Ok, I have a `find_account` method and a `claim_reward_balance` method, perfect. I thought I found everything I needed at this point and the Radiator code is readable and heavily commented, so let’s go. At this point my implementation looked like this: ```ruby # frozen_string_literal: true require 'rubygems' require 'bundler/setup' Bundler.require ACCOUNT_NAME = 'tipy' OPTIONS = { chain: :hive, wif: '5J*****************' }.freeze def pending_rewards chain = Radiator::Chain.new(OPTIONS) account_data = chain.find_account(ACCOUNT_NAME) account_data.slice( :reward_hive_balance, :reward_hbd_balance, :reward_vesting_balance ) end def claim_rewards(rewards) chain = Radiator::Chain.new(OPTIONS.merge(account_name: ACCOUNT_NAME)) chain.claim_reward_balance!( reward_hive: rewards.reward_hive_balance, reward_hbd: rewards.reward_hbd_balance, reward_vests: rewards.reward_vesting_balance ) end def empty_reward?(rewards) rewards.reward_hive_balance == '0.000 HIVE' && rewards.reward_hbd_balance == '0.000 HBD' && rewards.reward_vesting_balance == '0.000000 VESTS' end pr = pending_rewards if empty_reward?(pr) puts 'Nothing to claim' return end puts "Rewards: #{pr.to_h}" output = claim_rewards(pr) puts output ``` and it was not working… :( The code for making the claim_reward operation was throwing this exception: `{“error":"condenser_api.broadcast_transaction_synchronous: Assert Exception:is_asset_type( reward_hbd, HBD_SYMBOL ): Reward HBD must be expressed in HBD"} (Hive::UnexpectedAssetError)` Let’s look at the Radiator code: ```ruby # Create a claim_reward_balance operation. # # Examples: # # steem = Radiator::Chain.new(chain: :steem, account_name: 'your account name', wif: 'your wif') # steem.claim_reward_balance(reward_sbd: '100.000 SBD') # steem.broadcast! # # @param options [::Hash] options # @option options [String] :reward_steem The amount of STEEM to claim, like: `100.000 STEEM` # @option options [String] :reward_sbd The amount of SBD to claim, like: `100.000 SBD` # @option options [String] :reward_vests The amount of VESTS to claim, like: `100.000000 VESTS` def claim_reward_balance(options) reward_steem = options[:reward_steem] || '0.000 STEEM' reward_sbd = options[:reward_sbd] || '0.000 SBD' reward_vests = options[:reward_vests] || '0.000000 VESTS' @operations << { type: :claim_reward_balance, account: account_name, reward_steem: reward_steem, reward_sbd: reward_sbd, reward_vests: reward_vests } self end ``` Obviously, it cannot work, this piece of code only works for Steem (Radiator is an “high level” library which works for both Hive and Steem). But this method is just a kind of wrapper to create a Transaction, so I switched to transaction ```ruby def claim_rewards(rewards) tx = Radiator::Transaction.new(OPTIONS) tx.operations << { type: :claim_reward_balance, account: ACCOUNT_NAME, reward_hive: rewards.reward_hive_balance, reward_hbd: rewards.reward_hbd_balance, reward_vests: rewards.reward_vesting_balance } tx.process(true) end ``` and it’s still not working, but I made some progress, I’ve got an new error now: `{"error":"condenser_api.broadcast_transaction_synchronous: missing required posting authority:Missing Posting Authority tipy"} (Hive::MissingPostingAuthorityError)` WTF is this error? I have to admit I was a bit lost at this point so I asked for help on Discord. I thought my WIF key was wrong and I tried every Hive keys without any success, but the good point is I now have a clear understanding of the WIF format. I tried the code from the Javascript tutorial and my WIF key was the right one. So I tried to see if there were an issue with the Radiator code. I’m pretty sure there is one but I don’t know why. To be sure, the problem was in the Radiator code, I switched to hive-ruby (the library underneath Radiator): ```ruby def claim_rewards(rewards) options = OPTIONS.merge(params: { account: ACCOUNT_NAME, reward_hive: rewards.reward_hive_balance, reward_hbd: rewards.reward_hbd_balance, reward_vests: rewards.reward_vesting_balance }) Hive::Broadcast.claim_reward_balance(options) end ``` and it’s now working! --- At some points, I was really close to give up and move to Javascript, but instead I decided to explore the Radiator library, and I’m really glad I did. I learnt a lot about the library itself, and Hive internals. I don’t want to blame anyone with this post, just share my experience. Thanks inertia for maintaining the Radiator and hive-ruby librairies, I browsed the code enough to say it’s a great job. Maybe I’ll try to understand the Radiator code more and try to do some pull requests (but hey opensource depends on good will and it’s finally sunny here ;p). I’ve seen some vcr tests in the code and this is something I wanted to try myself for a long time, so this is maybe the right time to do it. The ruby documentation on Hive developer portal also needs some love. Hope you enjoyed my little adventure writing this piece of code. Happy coding!
author | tipy |
---|---|
permlink | digging-into-hive-ruby-library |
category | hive-169321 |
json_metadata | {"links":["https://developers.hive.io/tutorials","https://images.unsplash.com/photo-1522776851755-3914469f0ca2?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1500&q=80","https://developers.hive.io/tutorials-javascript/claim_rewards.html"],"users":["param","option","option","option","operations"],"tags":["hive-169321","programming","ruby","radiator","proofofbrain"],"app":"ecency/3.0.18-vision","format":"markdown+html"} |
created | 2021-08-11 06:24:21 |
last_update | 2021-08-11 06:24:21 |
depth | 0 |
children | 5 |
last_payout | 2021-08-18 06:24:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 1.074 HBD |
curator_payout_value | 1.070 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 6,416 |
author_reputation | 2,587,692,516,886 |
root_title | "Digging into Hive ruby library" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 105,455,317 |
net_rshares | 2,946,477,311,018 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
good-karma | 0 | 79,503,635,632 | 8.13% | ||
esteemapp | 0 | 26,833,071,065 | 8.13% | ||
tipy | 0 | 1,659,714,956 | 100% | ||
sanat | 0 | 106,923,218 | 100% | ||
esteem.app | 0 | 2,228,766,387 | 8.13% | ||
paulmoon410 | 0 | 513,909,331 | 4% | ||
photographercr | 0 | 3,061,568,633 | 1.62% | ||
davidlionfish | 0 | 32,277,641,949 | 33% | ||
hive-134220 | 0 | 395,141,314 | 9.3% | ||
ecency | 0 | 2,703,574,341,964 | 8.13% | ||
chloe.citation | 0 | 1,207,945,026 | 100% | ||
ecency.stats | 0 | 2,123,405,266 | 8.13% | ||
stayten | 0 | 43,898,486,236 | 100% | ||
mundo.curioso | 0 | 539,827,377 | 100% | ||
trippymane | 0 | 18,588,292,018 | 100% | ||
susamusic | 0 | 14,755,988,041 | 100% | ||
sralim | 0 | 11,243,028,338 | 50% | ||
biggestloser | 0 | 2,459,063,614 | 100% | ||
onwugbenuvictor | 0 | 1,176,555,714 | 60.4% | ||
foreach | 0 | 330,004,939 | 100% | ||
cyboule | 0 | 0 | 100% |
I know java, python, R also, but I don't know about Ruby. Feeling stupid now..... Great post by the way 👍
author | biggestloser | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
permlink | qxvydw | ||||||||||||||||||
category | hive-169321 | ||||||||||||||||||
json_metadata | {"app":"hiveblog/0.1"} | ||||||||||||||||||
created | 2021-08-15 14:46:45 | ||||||||||||||||||
last_update | 2021-08-15 14:46:45 | ||||||||||||||||||
depth | 1 | ||||||||||||||||||
children | 0 | ||||||||||||||||||
last_payout | 2021-08-22 14:46:45 | ||||||||||||||||||
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 | 108 | ||||||||||||||||||
author_reputation | 705,599,888,230 | ||||||||||||||||||
root_title | "Digging into Hive ruby library" | ||||||||||||||||||
beneficiaries |
| ||||||||||||||||||
max_accepted_payout | 1,000,000.000 HBD | ||||||||||||||||||
percent_hbd | 10,000 | ||||||||||||||||||
post_id | 105,558,060 | ||||||||||||||||||
net_rshares | 2,180,969,039 | ||||||||||||||||||
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
tipy | 0 | 2,180,969,039 | 100% |
Bonjour et merci de votre vote
author | cyboule |
---|---|
permlink | re-tipy-2021819t20246654z |
category | hive-169321 |
json_metadata | {"tags":["hive-169321","programming","ruby","radiator","proofofbrain"],"app":"ecency/3.0.19-vision","format":"markdown+html"} |
created | 2021-08-19 18:02:42 |
last_update | 2021-08-19 18:02:42 |
depth | 1 |
children | 0 |
last_payout | 2021-08-26 18:02: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 | 30 |
author_reputation | 47,399,155,158,214 |
root_title | "Digging into Hive ruby library" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 105,650,692 |
net_rshares | 0 |
**Yay!** 🤗<br>Your content has been **boosted with Ecency Points**, by @tipy. <br>Use Ecency daily to boost your growth on platform! <br><br><b>Support Ecency</b><br>[Vote for Proposal](https://hivesigner.com/sign/update-proposal-votes?proposal_ids=%5B141%5D&approve=true)<br>[Delegate HP and earn more](https://ecency.com/hive-125125/@ecency/daily-100-curation-rewards)
author | ecency |
---|---|
permlink | re-2021811t91944930z |
category | hive-169321 |
json_metadata | {"tags":["ecency"],"app":"ecency/3.0.16-welcome","format":"markdown+html"} |
created | 2021-08-11 09:19:45 |
last_update | 2021-08-11 09:19:45 |
depth | 1 |
children | 0 |
last_payout | 2021-08-18 09:19:45 |
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 | 370 |
author_reputation | 618,463,262,876,019 |
root_title | "Digging into Hive ruby library" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 105,457,355 |
net_rshares | 0 |
Congratulations @tipy! 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/@tipy/upvoted.png?202108110836"></td><td>You received more than 50 upvotes.<br>Your next target is to reach 100 upvotes.</td></tr> </table> <sub>_You can view your badges on [your board](https://hivebuzz.me/@tipy) 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>
author | hivebuzz |
---|---|
permlink | hivebuzz-notify-tipy-20210811t090640 |
category | hive-169321 |
json_metadata | {"image":["http://hivebuzz.me/notify.t6.png"]} |
created | 2021-08-11 09:06:39 |
last_update | 2021-08-11 09:06:39 |
depth | 1 |
children | 0 |
last_payout | 2021-08-18 09:06:39 |
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 | 614 |
author_reputation | 370,313,906,630,158 |
root_title | "Digging into Hive ruby library" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 105,457,160 |
net_rshares | 0 |
I’m not sure why you had trouble with Radiator. But maybe there was a bug 3 years ago. I went back to my original tutorial app to see if it still worked. I also updated it to use Hive examples: https://peakd.com/@inertia/stinkypete-rb-reward-claim-script-for-steem Yes, the devportal should also have a simplified tutorial for this. I should work on that.
author | inertia |
---|---|
permlink | re-tipy-sbns1s |
category | hive-169321 |
json_metadata | {"tags":["hive-169321"],"app":"peakd/2024.4.1"} |
created | 2024-04-09 04:49:03 |
last_update | 2024-04-09 04:49:03 |
depth | 1 |
children | 0 |
last_payout | 2024-04-16 04:49:03 |
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 | 361 |
author_reputation | 346,568,901,399,561 |
root_title | "Digging into Hive ruby library" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 132,717,349 |
net_rshares | 0 |