getBlockTime
Returns the estimated production time of a block.
Common use cases
| Convert slots to human-readable timestamps | Retrieve Unix timestamp for any slot to display block production time in user-friendly format. Common pattern: getSlot() → getBlockTime(slot) → new Date(timestamp * 1000) for frontend display. |
| Calculate block duration and time ranges | Fetch timestamps for multiple slots to compute average block time or find slot boundaries for date range queries. Example: compare getBlockTime(latestSlot) and getBlockTime(earlierSlot) to measure duration. |
| Annotate transactions with timestamps | Extract slot from transaction metadata then call getBlockTime(slot) to add human-readable timestamp to transaction history displays or blockchain explorers. |
| Epoch boundary timestamp calculation | Combine with getEpochSchedule() to determine first/last slot timestamps for any epoch using getBlockTime(epochSchedule.getFirstSlotInEpoch(epoch)). Essential for inflation rewards display and epoch-aligned analytics. |
| Frontend blockchain clock synchronization | Poll current slot and retrieve its timestamp to display "blockchain time" in dashboards, detect RPC node lag, or synchronize client-side events with blockchain progression. |
Parameters
slot number (u64, required)
Block number, identified by Slot
Request
- cURL
- JavaScript
- Python
curl https://solana-mainnet.api.syndica.io/api-key/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "getBlockTime",
"params": [
5
]
}'
// Using fetch
const response = await fetch('https://solana-mainnet.api.syndica.io/api-key/YOUR_API_KEY', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
"jsonrpc": "2.0",
"id": 1,
"method": "getBlockTime",
"params": [
5
]
})
});
const data = await response.json();
console.log(data);
import requests
import json
url = 'https://solana-mainnet.api.syndica.io/api-key/YOUR_API_KEY'
headers = {'Content-Type': 'application/json'}
data = {
"jsonrpc": "2.0",
"id": 1,
"method": "getBlockTime",
"params": [
5
]
}
response = requests.post(url, headers=headers, data=json.dumps(data))
print(response.json())
Replace mainnet with devnet in the URL to query devnet instead.
Response
{
"jsonrpc": "2.0",
"result": 1574721591,
"id": 1
}
FAQ and Troubleshooting
Why does getBlockTime return i64 instead of u64? Won't Solana block timestamps always be positive?
i64 is the standard Unix timestamp format supporting dates before January 1, 1970 (negative values). While Solana blocks will never have negative timestamps, using i64 maintains consistency with established timestamp conventions across programming languages and databases.
Why does getBlockTime return null immediately after getSlot() returns a slot?
Block timestamps are calculated from stake-weighted validator vote times, which takes 2-4 seconds to aggregate after block production. Either add delay/retry logic, or use finalized commitment for both calls to ensure timestamp is available.
How is block time calculated? Is it the exact production time?
Block time is the stake-weighted mean of Vote timestamps reported by validators who voted on the block. It's an estimated production time, not exact, since validators report times from their local clocks. Higher-stake validators have more influence on the final timestamp.
Can I use getBlockTime to get the current blockchain time?
Yes, use the pattern: const slot = await connection.getSlot(); const timestamp = await connection.getBlockTime(slot);. There's no direct "get current time" RPC method. Ensure consistent commitment levels (recommend finalized) to avoid null results.
What does it mean when getBlockTime returns null?
Null indicates the timestamp is not available for that slot, which happens for: (1) skipped slots that never produced blocks, (2) blocks not yet timestamped (too recent), or (3) blocks pruned from long-term storage. Use finalized commitment and check for null before processing.
Related Methods
getSlot
Returns current slot at specified commitment. Primary pattern: call getSlot() to get current slot then getBlockTime(slot) to retrieve blockchain timestamp for frontend clock synchronization.
getBlock
Returns block data including transactions. Block response includes blockTime field, so you can retrieve timestamp within full block data rather than separate getBlockTime call.
getEpochSchedule
Returns epoch schedule including slots per epoch. Combine with getBlockTime(epochSchedule.getFirstSlotInEpoch(epoch)) to calculate epoch boundary timestamps for rewards display.
getTransaction
Returns transaction details including slot. Extract slot from transaction metadata then call getBlockTime(slot) to annotate transactions with human-readable timestamps.
getBlockHeight
Returns block height (count of confirmed blocks). Use getBlockTime with block height for timestamp correlation in time-series analytics and historical data queries.
External Resources
- Solana Official Documentation
- Unix Time - Wikipedia - Background on Unix timestamp format (seconds since 1970-01-01 00:00:00 UTC), explains i64 signed integer standard and cross-platform timestamp conventions.