# getBlockCommitment

The `getBlockCommitment` RPC method provides insights into the **commitment status** of a specific block in the Solana ledger. It helps developers evaluate how much stake has voted on a block, making it a valuable tool for gauging **block finality** and **cluster health**.

***

#### **Common Use Cases**

* **Assessing Block Finality**\
  Measure the level of consensus by analyzing how much stake (in lamports) has confirmed the block across different confirmation depths.
* **Evaluating Cluster Health**\
  Use the `totalStake` field to understand the total active stake in the cluster when the block was processed.
* **Implementing Custom Confirmation Logic**\
  Ideal for systems that require stricter guarantees than standard `processed`, `confirmed`, or `finalized` commitment levels.

***

#### **Parameters**

* **`slot`** (*number, required*):\
  The slot number (u64) of the block for which commitment info is requested.

***

#### **Response**

If the block is found, the response includes:

* **`commitment`** (*array of u64 integers | null*):\
  An array (typically 32 elements) representing stake (in lamports) that voted on the block and its descendants up to depth `i`.
  * `commitment[i]` shows how much stake has confirmed the block at depth `i`.
  * `null` means the data is unavailable—either the block is too old or skipped.
* **`totalStake`** (*number*):\
  The total amount of active stake (in lamports) at the time the block was processed. Use this to calculate vote ratios like `commitment[i] / totalStake`.

#### **Example: Fetching Block Commitment Information**

Here’s a sample request using a placeholder slot (`355194322`). Be sure to use a **recent, confirmed slot** from Devnet or Mainnet:

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

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

async function getBlockCommitment(rpcUrl) {
  try {
    const response = await fetch(rpcUrl, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        jsonrpc: '2.0',
        id: 1,
        method: 'getBlockCommitment',
        "params": [
            355194322 
          ]
      }),
    });

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

getBlockCommitment(RPC_URL);
```

{% endtab %}

{% tab title="Python" %}

```python
import json
import asyncio
import aiohttp

async def get_block_commitment(rpc_url):
    try:
        payload = {
            "jsonrpc": "2.0",
            "id": 1,
            "method": "getBlockCommitment",
            "params": [
                355194322
            ]
        }
        
        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_commitment(RPC_URL)

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

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "jsonrpc": "2.0",
  "result": {
    "commitment": [
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      399444769122427100
    ],
    "totalStake": 399588547164198100
  },
  "id": 1
}
```

#### **Developer Tips**

* **Understanding the Commitment Array**\
  The higher the values at deeper indices, the more finalized the block is.
  * Example: If `commitment[31] / totalStake >= 2/3`, the block has reached supermajority finality.
* **Handling `null` Commitments**\
  This often indicates:
  * The block is too old and has been pruned.
  * The block was skipped or never processed.
* **When to Use `getBlockCommitment`**\
  It’s primarily for **advanced consensus or analytics** tools. For general use, prefer commitment-aware methods like `getTransaction` or `getBlock`.
* **Pruning Awareness**\
  Be mindful that some **RPC providers like CoinVera** may prune commitment data after a certain period.
* **Deep Commitment Knowledge Required**\
  To interpret results correctly, understand Solana’s **commitment levels**. Refer to Solana’s documentation for a full breakdown.


---

# 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/getblockcommitment.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.
