getBlockTime

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

The getBlockTime RPC method returns the estimated Unix timestamp for when a given block (identified by its slot number) was produced. The timestamp is expressed as seconds since the Unix epoch. This method is essential for aligning on-chain events with real-world time.


✅ Common Use Cases

  • Timestamping On-Chain Events Determine the approximate real-world time a block was created to timestamp program executions, transactions, or events.

  • Analyze Block Intervals Calculate time differences between slots to examine validator behavior, slot scheduling, or block spacing.

  • Correlate Off-Chain Events Match external data (e.g. trades, system logs) with blockchain activity using slot-to-time mapping.


🛠 Request Parameters

  • slot (u64, required): The slot number for which to retrieve the estimated production time.


📦 Response Structure

The result field will return:

  • timestamp (i64): The block’s estimated Unix timestamp (in seconds).

  • null: Returned if the timestamp is unavailable—typically because:

    • The block is too old and the data has been pruned.

    • The slot was skipped and has no associated block or timestamp.

💡 Example

Get Estimated Production Time for a Specific Slot

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getBlockTime",
  "params": [355104000]
}

Code Examples

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

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

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

getBlockTime(RPC_URL);

Example Response

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

📌 Replace 355104000 with a recent, confirmed slot number from your target cluster (e.g., Mainnet or Devnet).

🧠 Developer Tips

  • Timestamp Availability May Vary Older or skipped slots may return null. This is due to pruning or the absence of block production.

  • Estimated, Not Exact The returned timestamp is stake-weighted, based on vote timestamps. It’s generally accurate but not cryptographically guaranteed.

  • Node Variability Timestamps may differ slightly between RPC providers depending on validator reports and ledger history. For recent blocks, confirmation delays may affect availability.

Last updated