Ana içeriğe atla

Parametreler

slot
number
gerekli
Blok zamanının alınacağı slot

Yanıt

result
number | null
Bloğun üretildiği Unix zaman damgası veya blok mevcut değilse null

Kod Örnekleri

Temel İstek

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
  ]
}'

web3.js Kullanımı

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
  }));
}

Notlar

  1. Bloğun üretildiği Unix zaman damgasını döndürür
  2. Blok mevcut değilse null döndürür
  3. Zaman damgası Unix başlangıç noktasından itibaren saniye cinsindedir
  4. Blok zamanları tahmini değerlerdir ve düğümler arasında farklılık gösterebilir
  5. Eski bloklar için zaman damgası mevcut olmayabilir

En İyi Uygulamalar

  1. Null yanıtları uygun şekilde yönetin
  2. Görüntüleme için Unix zaman damgalarını Date nesnelerine dönüştürün
  3. Zamanları gösterirken saat dilimi farklılıklarını göz önünde bulundurun
  4. RPC yükünü azaltmak için uygun durumlarda sonuçları önbelleğe alın
  5. Bu metodu diğer blok metodlarıyla birlikte kullanın

Yaygın Hatalar

KodMesajÇözüm
-32601Method not foundBir Solana RPC düğümüne bağlı olduğunuzu doğrulayın
-32007Block time not availableBlok çok eski veya henüz üretilmemiş olabilir

Kullanım Senaryoları

  1. Blok Zaman Analizi
    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. Blok Zamanı Takibi
    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. Blok Üretim Hızı
    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
      };
    }