> ## Documentation Index
> Fetch the complete documentation index at: https://docs.orbitflare.com/llms.txt
> Use this file to discover all available pages before exploring further.

# getBlockTime

> Returns the estimated production time of a block

## Parameters

<ParamField query="slot" type="number" required>
  The slot to get the block time for
</ParamField>

## Response

<ResponseField name="result" type="number | null">
  Unix timestamp of when the block was produced, or null if the block is not available
</ResponseField>

## Code Examples

### Basic Request

```bash theme={null}
curl https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getBlockTime",
  "params": [
    100000000
  ]
}'
```

### Using web3.js

```typescript theme={null}
import { Connection } from '@solana/web3.js';

const connection = new Connection('https://fra.rpc.orbitflare.com?api_key=YOUR-API-KEY');

// Get block time
const blockTime = await connection.getBlockTime(100000000);
if (blockTime !== null) {
  console.log('Block time:', new Date(blockTime * 1000));
} else {
  console.log('Block not available');
}

// Get multiple block times
async function getBlockTimes(slots: number[]) {
  const times = await Promise.all(
    slots.map(slot => connection.getBlockTime(slot))
  );
  
  return times.map((time, index) => ({
    slot: slots[index],
    time: time ? new Date(time * 1000) : null
  }));
}
```

## Notes

1. Returns the Unix timestamp when the block was produced
2. Returns null if the block is not available
3. The timestamp is in seconds since Unix epoch
4. Block times are estimates and may vary between nodes
5. Older blocks may not have timestamps available

## Best Practices

1. Handle null responses appropriately
2. Convert Unix timestamps to Date objects for display
3. Consider timezone differences when displaying times
4. Cache results when appropriate to reduce RPC load
5. Use this method in conjunction with other block methods

## Common Errors

| Code   | Message                  | Solution                                     |
| ------ | ------------------------ | -------------------------------------------- |
| -32601 | Method not found         | Verify you're connected to a Solana RPC node |
| -32007 | Block time not available | Block may be too old or not yet produced     |

## Use Cases

1. **Block Time Analysis**
   ```typescript theme={null}
   interface BlockTimeMetrics {
     slot: number;
     time: Date | null;
     delay: number | null;
   }

   async function analyzeBlockTimes(startSlot: number, endSlot: number) {
     const blocks = await connection.getBlocks(startSlot, endSlot);
     const times = await Promise.all(
       blocks.map(slot => connection.getBlockTime(slot))
     );
     
     const metrics: BlockTimeMetrics[] = blocks.map((slot, index) => {
       const time = times[index];
       const prevTime = index > 0 ? times[index - 1] : null;
       
       return {
         slot,
         time: time ? new Date(time * 1000) : null,
         delay: time && prevTime ? time - prevTime : null
       };
     });
     
     return metrics;
   }
   ```

2. **Block Time Tracking**
   ```typescript theme={null}
   interface BlockTimeHistory {
     slot: number;
     timestamp: number;
     date: Date;
   }

   async function trackBlockTimes(slots: number[]) {
     const times = await Promise.all(
       slots.map(slot => connection.getBlockTime(slot))
     );
     
     const history: BlockTimeHistory[] = times
       .filter((time, index) => time !== null)
       .map((time, index) => ({
         slot: slots[index],
         timestamp: time!,
         date: new Date(time! * 1000)
       }));
     
     return history;
   }
   ```

3. **Block Production Rate**
   ```typescript theme={null}
   async function calculateBlockProductionRate(startSlot: number, endSlot: number) {
     const blocks = await connection.getBlocks(startSlot, endSlot);
     const times = await Promise.all(
       blocks.map(slot => connection.getBlockTime(slot))
     );
     
     const validTimes = times.filter(time => time !== null) as number[];
     if (validTimes.length < 2) {
       return null;
     }
     
     const firstTime = validTimes[0];
     const lastTime = validTimes[validTimes.length - 1];
     const totalTime = lastTime - firstTime;
     const blocksPerSecond = validTimes.length / totalTime;
     
     return {
       blocksPerSecond,
       totalTime,
       totalBlocks: validTimes.length
     };
   }
   ```
