Last active
August 29, 2025 13:02
-
-
Save benjaminion/4ebe2495de6fa79270991164dd788c50 to your computer and use it in GitHub Desktop.
Validator daily rewards
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python3 | |
| import sys | |
| import json | |
| import urllib3 | |
| from datetime import datetime, timezone, timedelta | |
| start_date = datetime.fromisoformat('2025-05-10 23:59:59+00:00') | |
| end_date = datetime.fromisoformat('2025-05-12 23:59:59+00:00') | |
| day = timedelta(days=1) | |
| # Nodereal.io | |
| NODE_API = 'https://eth2-beacon-mainnet.nodereal.io/v1/<API-KEY>' | |
| VALIDATOR = <VALIDATOR-INDEX> | |
| GWEI_PER_ETH = 10**9 | |
| GENESIS = datetime.fromisoformat('2020-12-01 12:00:23+00:00').timestamp() | |
| SECONDS_PER_SLOT = 12 | |
| http = urllib3.PoolManager() | |
| def get_balance(date): | |
| slot = int((date.timestamp() - GENESIS) / SECONDS_PER_SLOT) | |
| request_url = NODE_API + '/eth/v1/beacon/states/' + str(slot) + '/validator_balances?id=' + str(VALIDATOR) | |
| response = http.request('GET', request_url) | |
| return int(json.loads(response.data)['data'][0]['balance']) | |
| date = start_date - day | |
| new_balance = get_balance(date) | |
| while date < end_date: | |
| date += day | |
| old_balance = new_balance | |
| new_balance = get_balance(date) | |
| print('Staking,%.9f,ETH,,,,,,,,Eth2,%s,%.9f' % ((new_balance - old_balance) / GWEI_PER_ETH, date.strftime('%Y-%m-%d %H:%M:%S'), new_balance / GWEI_PER_ETH)) | |
| sys.stdout.flush() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment