We are building a delegator dashboard,
I was wondering how can we calculate projected vs actual rewards using the Tzscan API?
Thanks
Tezos Stack Exchange is a question and answer site for users, experts, and developers of the Tezos blockchain project. It only takes a minute to sign up.
Sign up to join this communityWe are building a delegator dashboard,
I was wondering how can we calculate projected vs actual rewards using the Tzscan API?
Thanks
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'])