5

We are building a delegator dashboard,

I was wondering how can we calculate projected vs actual rewards using the Tzscan API?

Thanks

1
  • Can you explain, if you want to do the calculation by yourself or do you want to pull the already calculated results from tzscan?
    – jdsika
    Commented Feb 9, 2019 at 18:55

1 Answer 1

5

Solution Part 1:

How to calculate actual rewards using the tzscan.io API?

One of the first payout scripts using the tzscan API was released and published in Reddit. It is licensed under MIT and it is a Python script which is very easy to understand and short. Here are some code snippets:

# TzScan API URLs
api_url_head = 'https://api{}.tzscan.io/v2/head'.format(api_mirror) # info about current status
api_url_rewards = 'http://api{}.tzscan.io/v2/rewards_split/'.format(api_mirror) # info about rewards at specific cycle

# get current cycle info
response = urllib.request.urlopen(api_url_head)
data = json.loads(response.read())

####################
# get rewards data #
####################
page = 0
response = urllib.request.urlopen('{}{}?cycle={}&number=50&p={}'.format(api_url_rewards, baker_address, cycle, page))
data = json.loads(response.read())

print('\n')

total_delegators = int(data['delegators_nb'])
if total_delegators == 0:
    print('No non-baker delegators for cycle ', format(cycle), '.')

pages = total_delegators / 50

paid_delegators = 0

total_staking_balance = int(data['delegate_staking_balance'])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.