getBlockCommitment

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

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:

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

Example Response

{
  "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.

Last updated