getSlot

Learn about getSlot—its use cases, code examples, request parameters, response structure, and helpful tips.

The getSlot RPC method in CoinVera returns the current slot number that the node believes has reached a specified commitment level. This is a core method used to understand the current progression of the Solana blockchain as perceived by an RPC node.


✅ Common Use Cases

  • Getting Current Network Progress Identify the most recent slot processed or confirmed by the node.

  • Node Synchronization Check Compare slot values between nodes to assess sync status.

  • Timestamping Operations Use slot values as temporal markers for blockchain events or data.

  • Input for Other RPC Calls Supply a current or specific slot as input to other RPC methods.


🧾 Request Parameters

This method accepts an optional configuration object:

  • options (object, optional):

    • commitment (string, optional): Determines the commitment level to query. Options:

      • processed: Latest slot the node knows of. Not confirmed—may be skipped.

      • confirmed: Slot voted on by a supermajority.

      • finalized: Slot confirmed and cannot be rolled back.

      • If omitted, defaults to the node’s default commitment (usually finalized).

    • minContextSlot (number, optional): The minimum acceptable slot. If the node is behind this slot, it may return an error or a lower value. Useful for ensuring queries operate on recent enough state.


📦 Response Structure

The result is a single unsigned 64-bit integer (u64):

{
  "result": 221446599
}

This value represents the slot number corresponding to the specified commitment level.


🧪 Examples

1. Get Current Slot (Default Commitment)

Fetches the slot using the node’s default setting, usually finalized.

{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getSlot"
}

2. Get Slot with Specific Commitment

Retrieve the latest slot at the confirmed commitment level.

{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getSlot",
    "params": [
      {
        "commitment": "confirmed"
      }
    ]
}

Code Examples

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

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

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

getSlot(RPC_URL);

Example Response

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": 355395938
}

💡 Developer Tips

  • Commitment Level Affects Finality Use finalized for the highest confidence. processed gives the most up-to-date slot but may not be stable.

  • Different Nodes, Different Slots Slot numbers can vary slightly between nodes, depending on network delays and processing state.

  • Use minContextSlot in Advanced Scenarios This helps ensure the node is evaluating your request against a recent enough slot. Especially useful in consistency-sensitive operations.


The getSlot method is simple but powerful—essential for understanding Solana's real-time state and building reliable, time-sensitive blockchain applications with CoinVera.

Last updated