Hive Developer logo

Hive Developer Portal

PY: Claim Rewards

How to claim rewards using Python.

Full, runnable src of Claim Rewards can be downloaded as part of: tutorials/python.

In this tutorial we show you how to check the HIVE, HBD and HIVE POWER rewards balances of an account on the Hive blockchain, and how to claim either a portion or all of the rewards for an account using the commit class found within the steem-python library.


The Hive python library has a built-in function to transmit transactions to the blockchain. We are using the claim_reward_balance method found within the commit class in the library. Before we transmit a claim, we use the get_account function to check the current rewards balance of the account to see what is available to claim. The claim method has 4 parameters:

  1. reward hive - The amount of HIVE to claim
  2. reward hbd - The amount of HBD to claim
  3. reward vests - The amount of VESTS (HIVE POWER) to claim
  4. account - The source account for the claim


  1. App setup - Library install and import. Connection to testnet
  2. User information and steem node - Input user information and connection to Hive node
  3. Check reward balance - Check current rewards balances of user account
  4. Claim commit - Input amount of rewards to claim and commit to blockchain
  5. Balance update - Check new rewards balances after completed claim

1. App setup

In this tutorial we use 2 packages:

We import the libraries and connect to the testnet.

import steembase
import steem
from pick import pick
from steem.amount import Amount

steembase.chains.known_chains['HIVE'] = {
    'chain_id': '79276aea5d4877d9a25892eaa01b0adf019d3e5cb12a97478df3298ccdd01673',
    'prefix': 'STX', 'hive_symbol': 'HIVE', 'hbd_symbol': 'HBD', 'vests_symbol': 'VESTS'

Because this tutorial alters the blockchain we connect to a testnet so we don’t create spam on the production server.

2. User information and steem node

We require the private active key of the user in order for the claim to be committed to the blockchain. This is why we are using a testnet. The values are supplied via the terminal/console before we initialise the steem class. There are some demo accounts available but we encourage you to create your own accounts on this testnet and create balances you can claim; it’s good practice.

#capture user information
username = input('Enter username: ') #demo account: cdemo
wif = input('Enter private ACTIVE key: ') #demo account: 5KaNM84WWSqzwKzY82fXPaUW43idbLnPqf5SfjGxLfw6eV2kAP3

#connect node
client = steem.Hive(nodes=[''],keys=[wif])

3. Check reward balance

We send a query to the blockchain using the get_account function to check if the username exists on the blockchain. We also use this function to get a clear picture of the available rewards that can be claimed and display this on the console/terminal.

#get account reward balances
userinfo = client.get_account(username)

if(userinfo is None) :
    print('Oops. Looks like user ' + username + ' doesn\'t exist on this chain!')

reward_hive = userinfo['reward_hive_balance']
reward_hbd = userinfo['reward_hbd_balance']
reward_sp = userinfo['reward_vesting_hive']
reward_vests = userinfo['reward_vesting_balance']

print('Reward Balances:' + '\n' + 
    'HIVE: ' + reward_hive + '\n' + 
    'HBD: ' + reward_hbd + '\n' + 
    'HIVE POWER: ' + reward_sp + '\n' +
    'VESTS: ' + reward_vests

input('\n' + 'Press enter to continue to claim selection')

4. Claim commit

An option is provided to either claim all rewards at once or to specify specific amounts to be claimed for each individual reward balance. If you are using one of Hive’s demo accounts, please leave some rewards for others to claim!

#choice of claim
title = 'Please choose claim type: '
options = ['ALL', 'SELECTED', 'CANCEL']
option, index = pick(options, title)

When the option to claim all rewards is selected, the claim parameters are automatically assigned from the get_accounts query. We also check that there are in fact outstanding rewards balances before we commit the claim.

#commit claim based on selection
if option == 'ALL':
    if Amount(reward_hive).amount + Amount(reward_hbd).amount + Amount(reward_vests).amount == 0:
        print('\n' + 'No rewards to claim')
        client.claim_reward_balance(reward_hive, reward_hbd, reward_vests, username)
        print('\n' + 'All reward balances have been claimed. New reward balances are:' + '\n')
    if option == 'CANCEL':
        print('\n' + 'Operation cancelled')
        claim_hive = input('\n' + 'Please enter the amount of HIVE to claim: ') + ' HIVE'
        claim_hbd = input('Please enter the amount of HBD to claim: ') + ' HBD'
        claim_vests = input('Please enter the amount of VESTS to claim: ') + ' VESTS'
        if Amount(claim_hive).amount + Amount(claim_hbd).amount + Amount(claim_vests).amount == 0:
            print('\n' + 'Zero values entered, no claim to submit')
            if claim_hive > reward_hive or claim_hbd > reward_hbd or claim_vests > reward_vests:
                print('\n' + 'Requested claim value higher than available rewards')
                client.claim_reward_balance(claim_hive, claim_hbd, claim_vests, username)
                print('\n' + 'Claim has been processed. New reward balances are:' + '\n')

When doing only a selected claim of available rewards, the values are captured in the console/terminal. The inputs cannot be negative, must be less than or equal to the available reward and at least ONE of the inputs needs to be greater than zero for the claim to be able to transmit. The result of the selected option is printed on the UI.

5. Balance update

As a final check we run the account query again to get updated values for the available rewards balances.

#get updated account reward balances
input("Press enter for new account balances")

userinfo = client.get_account(username)

reward_hive = userinfo['reward_hive_balance']
reward_hbd = userinfo['reward_hbd_balance']
reward_sp = userinfo['reward_vesting_hive']
reward_vests = userinfo['reward_vesting_balance']

print('HIVE: ' + reward_hive + '\n' + 
    'HBD: ' + reward_hbd + '\n' + 
    'HIVE POWER: ' + reward_sp + '\n' +
    'VESTS: ' + reward_vests

We encourage users to play around with different values and data types to fully understand how this process works. You can also check the balances and transaction history on the testnet portal.

To Run the tutorial

  1. review dev requirements
  2. git clone
  3. cd devportal/tutorials/python/23_claim_rewards
  4. pip install -r requirements.txt
  5. python
  6. After a few moments, you should see a prompt for input in terminal screen.