# getBlockProduction

The `getBlockProduction` RPC method provides detailed insights into **block production statistics** within a specific slot range or the current epoch. It is particularly useful for monitoring **validator performance**, analyzing **network participation**, and detecting **missed leader slots**.

***

#### **Common Use Cases**

* **Monitor Validator Performance**\
  Track how many leader slots were assigned and how many blocks a validator actually produced.
* **Analyze Epoch-Wide Participation**\
  View block production data across all validators within the current or a historical epoch.
* **Detect Missed Slots**\
  Identify whether a validator missed their assigned slots, helping measure uptime or reliability.
* **Assess Network Health**\
  Evaluate overall block production efficiency as part of broader network monitoring.

***

#### **Request Parameters**

You can call `getBlockProduction` with an optional configuration object:

* **`commitment`** (*string, optional*):\
  Determines the commitment level to use. Defaults to the node’s configured level.
* **`range`** (*object, optional*):\
  Specifies the slot range to examine.
  * `firstSlot` (*u64*, required if no `identity`): Start slot (inclusive).
  * `lastSlot` (*u64*, optional): End slot (inclusive). If omitted, data will be returned up to the current slot.
* **`identity`** (*string, optional*):\
  The base58-encoded public key of a validator. If specified, returns data only for that validator.\
  ⚠️ Either `identity` or `range.firstSlot` **must** be provided.

***

#### **Response Structure**

* **`context`** (*object*):
  * `slot`: The slot at which the query was evaluated.
* **`value`** (*object*):
  * `byIdentity`: An object mapping each validator’s identity (public key) to:
    * `leaderSlots`: Number of slots assigned.
    * `blocksProduced`: Number of blocks successfully produced.
  * `range`:
    * `firstSlot`: Start of the queried range.
    * `lastSlot`: End of the queried range.

#### **Examples**

**1. Get Block Production for Current Epoch (All Validators)**

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getBlockProduction"
}
```

2. **Get Block Production for a Specific Validator (Current Epoch)**

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getBlockProduction",
  "params": [
    {
      "identity": "YourValidatorPublicKeyHere"
    }
  ]
}
```

3. **Get Block Production for a Validator in a Slot Range**

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getBlockProduction",
  "params": [
    {
      "identity": "YourValidatorPublicKeyHere",
      "range": {
        "firstSlot": 355104000,
        "lastSlot": 355104010
      }
    }
  ]
}

```

**Code Examples**

{% tabs %}
{% tab title="Nodejs" %}

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

async function getBlockProduction(rpcUrl) {
  try {
    const response = await fetch(rpcUrl, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        jsonrpc: '2.0',
        id: 1,
        method: 'getBlockProduction',
        "params": [
            {
              "identity": "85iYT5RuzRTDgjyRa3cP8SYhM2j21fj7NhfJ3peu1DPr",
              "range": {
                "firstSlot": 355104000, // e.g., 355104000
                "lastSlot": 355104010    // e.g., 355104010
              }
            }
          ]
      }),
    });

    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';

getBlockProduction(RPC_URL);
```

{% endtab %}

{% tab title="Python" %}

```python
import json
import asyncio
import aiohttp

async def get_block_production(rpc_url):
    try:
        payload = {
            "jsonrpc": "2.0",
            "id": 1,
            "method": "getBlockProduction",
            "params": [
                {
                    "identity": "85iYT5RuzRTDgjyRa3cP8SYhM2j21fj7NhfJ3peu1DPr",
                    "range": {
                        "firstSlot": 355104000,  # e.g., 355104000
                        "lastSlot": 355104010    # e.g., 355104010
                    }
                }
            ]
        }
        
        async with aiohttp.ClientSession() as session:
            async with session.post(
                rpc_url,
                headers={'Content-Type': 'application/json'},
                json=payload
            ) as response:
                data = await response.json()
                
                # Print the exact full response
                print('Full RPC Response:')
                print(json.dumps(data, indent=2))
                
                return data
                
    except Exception as error:
        print(f'Error getting health: {error}')
        return None

# Example usage
async def main():
    RPC_URL = 'https://rpc.coinvera.io/?x-api-key=your-coinvera-x-api-key'
    await get_block_production(RPC_URL)

# Run the async function
if __name__ == "__main__":
    asyncio.run(main())
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "jsonrpc": "2.0",
  "result": {
    "context": {
      "apiVersion": "2.2.16",
      "slot": 355197308
    },
    "value": {
      "byIdentity": {},
      "range": {
        "firstSlot": 355104000,
        "lastSlot": 355104010
      }
    }
  },
  "id": 1
}
```

This guide should give you a solid understanding of how to use the `getBlockProduction` RPC method to monitor and analyze validator and network block production on Solana.

#### **Developer Tips**

* **Epoch Boundaries Matter**\
  If querying by `identity` only, results are scoped to the current epoch up to the latest processed slot. For past epochs, use `range.firstSlot` and `range.lastSlot`.
* **Data Retention Depends on RPC Node**\
  Older slot ranges may not be available on all providers. CoinVera’s node infrastructure may retain more recent data.
* **Essential for Validator Monitoring**\
  This RPC is ideal for building dashboards that display block production stats, uptime, and slot efficiency metrics.
* **Enhance with `getLeaderSchedule`**\
  Pair with `getLeaderSchedule` to get a detailed view of when each validator was expected to produce blocks.
* **Large Data Sets Warning**\
  If querying without specifying an `identity`, and over a wide slot range, expect large responses. Limit the range or filter by identity for efficient processing.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.coinvera.io/integration/solana/rpc/getblockproduction.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
