On scan.pulsechain (blockscout), I see under “Withdrawals” the latest rewards that I received from my validator.
Has anyone written a Python script ideally based on web3.py library that grabs all the payouts produced by a validator (or wallet address) and show the total rewarded amount (sum)?
The address I use with my vaildators was used just for the deposit and the withdrawals, so it was empty after I deposited and got them running. I wrote a very simple script that just checks the balance of that account and writes it to a csv file. I have yet to take any pulse of of that account; if I do I’ll have to modify it.
Here you go Marculix.
I’m describing it below in a basic way for anyone else that reads this and doesn’t have much experience with the terminal.
It’s a python script. You need to set the URL for the RPC of your validator. Don’t expose yours if you aren’t confident in what you are doing. Since it is just checking the balance of the address, you could use a public RPC server too.
Put your validator address in the appropriate spot below. Remove the <> in both cases, but keep the single quotes ’ '.
All it does is get the balance from the address, formats and inserts the date and writes it on a new row in a CSV file. It doesn’t calculate or show and rewards, just gets the balance of the account, which could be any account, it doesn’t really have anything to do with the vaildator.
Make a new CSV file before the first run named val_balance.csv(or change the name in the code) and put ‘date’ in A1 and ‘balance’ in A2.
It then calls the program ‘cvslook’ to display the CSV file in the terminal so I don’t have to open the CSV file to see the balance.
This is on Linux.
You could drop the last line and run it in a cron job if you wanted to. I just run it every few days or so when I’m curious.
No warranty implied, etc…
import os
from datetime import date
from web3 import Web3
from eth_utils import from_wei
import decimal
import csv
w3 = Web3(Web3.HTTPProvider('http:<enter url here>'))
balance = w3.eth.get_balance('<validator address here>')
h_balance = w3.from_wei(balance, 'ether')
fb = '{:.6f}'.format(h_balance)
date = date.today()
row = {'date': date, 'balance': fb}
with open('val_balance.csv', 'a', newline='') as f:
field_name =['date', 'balance']
writer = csv.DictWriter(f, fieldnames=field_name)
writer.writerow(row)
os.system('csvlook val_balance.csv')```
Thanks so much for sharing Kolvir and sorry for the late reply!
I meanwhile wrote a korn-shell script mirrored on my website that satisfied my needs. I will enrich it with the validator rewards based on your input soon. Virtual beer to you.