getInflationReward

Learn getInflationReward use cases, code examples, request parameters, response structure, and tips.

The getInflationReward RPC method enables querying inflation rewards (staking rewards) for one or more accounts for a specific epoch. These rewards are credited to stake accounts, and the method is crucial for tracking, auditing, or verifying staking-based earnings.


βœ… Common Use Cases

  • πŸ” Verify Staking Rewards: Confirm that a stake account received rewards for a specific epoch.

  • πŸ“Š Track Reward History: Retrieve rewards across multiple epochs to analyze trends or build a payout log.

  • πŸ” Audit Validator Payouts: While validators don’t receive rewards directly, this method allows validating rewards received by their associated vote/stake accounts.


πŸ› οΈ Request Parameters

The method accepts:

1. addresses (array of strings) β€” Required

  • A list of base-58 encoded public keys.

  • These can be stake accounts, vote accounts, or other account types.

  • Some providers (like Helius) support large batches (e.g., up to 1005 addresses for paid users).

2. config (object) β€” Optional

Contains:

Field
Type
Description

commitment

string

Commitment level (processed, confirmed, or finalized). Default: finalized.

epoch

integer

The epoch number to query. If omitted, defaults to the most recently completed epoch.

minContextSlot

integer

Ensures the query is evaluated at a slot at least this recent.


πŸ“€ Example Request

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getInflationReward",
  "params": [
    ["AccountPublicKey1", "AccountPublicKey2"],
    {
      "epoch": 512,
      "commitment": "finalized"
    }
  ]
}

πŸ“₯ Response Structure

Returns an array of results, in the same order as the addresses array. Each element is either:

  • An object with reward info

  • null if the account received no rewards or didn’t exist in the epoch

Reward Object Fields:

Field
Type
Description

epoch

u64

Epoch number for the reward

effectiveSlot

u64

Slot in which the reward was applied

amount

u64

Reward amount in lamports

postBalance

u64

Account balance after reward application

commission

u8

Validator’s commission percentage (only for vote accounts)


Code Examples

const fetch = require('node-fetch');

async function getInflationReward(rpcUrl) {
  try {
    const response = await fetch(rpcUrl, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        jsonrpc: '2.0',
        id: 1,
        method: 'getInflationReward',
        "params": [
            [
              "6dmNQ5jwLeLk5REvio1JcMshcbvkYMwy26sJ8pbkvStu",
              "BGsqMegLpV6n6Ve146sSX2dTjUMj3M92HnU8BbNRMhF2"
            ],
            {
              "epoch": 822,
              "commitment": "finalized"
            }
          ]
      }),
    });

    const data = await response.json();
    
    // Print the exact full response
    console.log('Full RPC Response:');
    console.log(JSON.stringify(data, null, 2));
    
    return data;
  } catch (error) {
    console.error('Error getting health:', error.message);
    return null;
  }
}

// Example usage
const RPC_URL = 'https://rpc.coinvera.io/?x-api-key=your-coinvera-x-api-key';

getInflationReward(RPC_URL);

Example Response

{
  "jsonrpc": "2.0",
  "error": {
    "code": -32004,
    "message": "Block not available for slot 355536000"
  },
  "id": 1
}

πŸ’‘ Developer Tips

  • Epoch Timing: Rewards are calculated at the end of an epoch and credited at the start of the next.

  • Effective Slot: Indicates when the reward was actually applied.

  • Null Entries: May mean:

    • The account didn't exist

    • No rewards were applicable (e.g., inactive or insufficient stake)

    • The reward was zero

  • Batch Requests: Avoid overloading providers with large batches if you're not sure about their rate limits.

  • Use with getEpochInfo: To dynamically determine the current or most recent epoch before querying.


πŸ“˜ Summary

The getInflationReward RPC method is an essential tool for any staking dashboard, validator analytics tool, or protocol-level reward verification system. It gives granular visibility into how inflation rewards are distributed per epoch across stake accounts.

Last updated