Solana pull history of staking (inflation) rewards associated with given address

Viewed 303

I can pull the staking rewards (inflation rewards) associated with a particular Solana address using the following:

import requests
import json

url = "https://api.mainnet-beta.solana.com"


payload = {
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getInflationReward",
  "params": [
     [my_staking_address], {"epoch": 231}
  ]
}


response = requests.post(url, json=payload).json()
print(response)

The issue with this is that I have to specify the epoch. Is it possible to get a list of all staking rewards associated with the address in a single request? It will take a while to iterate over each epoch.

I'm just hoping there is a better way to get the history of inflation rewards than creating a new request for each epoch.

1 Answers

This isn't possible at the moment unfortunately, so you'll have to iterate through those epochs to know the rewards for the given account. If it's any consolation, inflation was only enabled on mainnet in slot 64800004, epoch 150, so for the current epoch as of this writing (235), it's doable. We would need to add more features to the RPC call to fully support what you're asking.

Another possible option is to calculate rewards based on the vote accounts from getVoteAccounts https://docs.solana.com/developing/clients/jsonrpc-api#getvoteaccounts, but I believe you'll still need the inflation governor for each epoch to get an actual reward amount in lamports, making

Related