Migrate Solana getConfirmedBlock Calls to getBlock

Replace the deprecated Solana getConfirmedBlock RPC method with getBlock in a Node.js script, including version-aware requests and practical error handling.

Replace getConfirmedBlock with getBlock and pass the slot as the first parameter. This Node.js 18+ example requests a confirmed block, handles common RPC failures, and prints the slot and block time. Set SOLANA_RPC_URL to your Solana RPC endpoint before running it.

Replace the method and request parameters

Solana deprecated getConfirmedBlock in favor of getBlock. The method name changes, while the slot remains the first parameter. The example requests full transaction details at confirmed commitment and sets maxSupportedTransactionVersion to 0 so the request can include version 0 transactions.

For an endpoint, use your configured Solana RPC URL or review OnFinality’s Solana network page. The network page is a destination for network information; do not treat it as an RPC URL.

    JavaScript · Node.js
    const endpoint = process.env.SOLANA_RPC_URL;
    const slot = Number(process.env.SLOT);
    
    if (!endpoint) {
      console.error('Set SOLANA_RPC_URL to your Solana RPC endpoint.');
      process.exit(1);
    }
    if (!Number.isSafeInteger(slot) || slot < 0) {
      console.error('Set SLOT to a non-negative integer slot number.');
      process.exit(1);
    }
    
    const request = {
      jsonrpc: '2.0',
      id: 1,
      method: 'getBlock',
      params: [slot, {
        commitment: 'confirmed',
        transactionDetails: 'full',
        rewards: false,
        maxSupportedTransactionVersion: 0
      }]
    };
    
    try {
      const response = await fetch(endpoint, {
        method: 'POST',
        headers: { 'content-type': 'application/json' },
        body: JSON.stringify(request)
      });
    
      if (!response.ok) {
        throw new Error(`HTTP ${response.status} ${response.statusText}`);
      }
    
      const body = await response.json();
      if (body.error) {
        throw new Error(`RPC ${body.error.code}: ${body.error.message}`);
      }
      if (body.result === null) {
        console.error(`No confirmed block was returned for slot ${slot}. It may not be available at this commitment.`);
        process.exitCode = 2;
      } else {
        console.log(JSON.stringify({ slot, blockTime: body.result.blockTime }, null, 2));
      }
    } catch (error) {
      console.error(`getBlock request failed: ${error.message}`);
      process.exitCode = 1;
    }

    Run it with SOLANA_RPC_URL set to your endpoint and SLOT set to a slot number, for example: SOLANA_RPC_URL="$YOUR_RPC_URL" SLOT=123 node get-block.mjs. Replace the example slot with one you want to inspect.

    For a successful response, the script prints JSON with the requested slot and the block’s blockTime; the time can be null. An RPC error is reported with its code and message. A null result is handled separately because the endpoint did not return a block for that slot at the requested commitment.

    Handle transaction version limits

    The maxSupportedTransactionVersion field tells the RPC node which transaction versions the client can handle. This example sets it to 0, which supports legacy and version 0 transactions. If you omit the field, a block containing versioned transactions may produce an error. Update the value only after your application can parse the versions it advertises.

    If the RPC response still reports an unsupported transaction version, inspect the error and adjust the client’s supported version deliberately. Do not assume that changing the method name alone resolves transaction decoding issues.

      You can compare the response shape with the `getBlock` JSON-RPC reference.

      Choose RPC reads or indexed queries

      getBlock is an RPC read for a particular slot. Migrating this call does not create an index or provide indexed search across a program’s history. If your task is to query filtered or aggregated on-chain data, identify an indexing solution and verify that it indexes the data and fields your application needs.

      For help forming a Solana RPC request, use OnFinality RPC Assistant. For guides on related Solana development tasks, continue with OnFinality Learn.