Posts

Claiming Discounted Hive Accounts Using Beem

avatar of @geekgirl
25
@geekgirl
·
·
0 views
·
2 min read

Beem is a great python library to interact with Hive Blockchain. It is created and maintained by @holger80.

Hive has discounted accounts. Anybody who has enough resource credits can claim these discounted account tokens at the cost of their available RC. At a later time new accounts can be created using these claims for free. From time to time I claim some accounts with intention to use them in the future or help other onboarding efforts.

Normally I would use peakd to claim accounts. In the wallet section, under delegate they have an option to claim accounts. They used to provide two options: single account claim, and multiple accounts claim. For some reason the multiple accounts claim option is not there anymore. Maybe it has moved somewhere else on the website. Instead of figuring out what happened to that option, I decided to see if I could achieve the same results using Beem.

As I was going looking for the ways how to write this script, I came across Holger's post from three years ago on the same topic. Holder gives a detailed explanation with the codes on how to claim discounted account and also how to create accounts using Beem in python. Here is the post:

Since the post is from three years ago, it is written for Steem blockchain. The code was so easy to follow, and I was able to repurpose it for Hive blockchain without any difficulty.

I had to make changes so that it works with Hive. The original code was written to claim one account at a time. But it was written so well, it was very easy to change it to claim multiple accounts. I left the option for claiming one account in the code as commented out lines.

Here is my final code:

from beem import Hive 
from beem.nodelist import NodeList 
from beem.account import Account 
from beem.rc import RC 
import pprint 
import getpass 
import time 
 
if __name__ == "__main__": 
 
    nodelist = NodeList() 
    nodelist.update_nodes() 
    nodes = nodelist.get_hive_nodes() 
 
    wif = getpass.getpass(prompt='Enter your Hive active key:') 
    hive = Hive(node=nodes, keys=[wif]) 
 
    creator = hive.wallet.getAccountFromPrivateKey(wif) 
    creator = Account(creator) 
 
    rc = RC(blockchain_instance=hive) 
    current_costs = hive.get_rc_cost(rc.get_resource_count(tx_size=250, new_account_op_count=1, execution_time_count=1)) 
    current_mana = creator.get_rc_manabar()["current_mana"] 
    last_mana = current_mana 
    print("Current costs %.2f G RC - current mana %.2f G RC" % (current_costs / 1e9, current_mana / 1e9)) 
 
    # if current_costs + 10 < current_mana: 
    #     hive.claim_account(creator) 
    #     time.sleep(10) 
    #     creator.refresh() 
    #     current_mana = creator.get_rc_manabar()["current_mana"] 
    #     print("Account claimed and %.2f G RC paid." % ((last_mana - current_mana) / 1e9)) 
    #     last_mana = current_mana 
    # else: 
    #     print("Not enough RC for a claim!") 
         
    while current_costs + 10 < last_mana: 
        hive.claim_account(creator) 
        time.sleep(10) 
        creator.refresh() 
        current_mana = creator.get_rc_manabar()["current_mana"] 
        print("Account claimed and %.2f G RC paid." % ((last_mana - current_mana) / 1e9)) 
        last_mana = current_mana 
     
    print("Not enough RC for a claim!") 

I didn't get a chance to play with creating accounts part of Holger's guide. I will try to do that soon and if successful will share here in the future.

If you have questions or suggestions let me know in the comments. Thank You.

Posted Using LeoFinance Beta