Ana içeriğe atla

Parametreler

Bu metod herhangi bir parametre almaz.

Yanıt

result
string
Base-58 kodlu dize olarak genesis hash

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": "getGenesisHash"
}'

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 genesis hash
const genesisHash = await connection.getGenesisHash();
console.log('Genesis hash:', genesisHash);

// Verify cluster
async function verifyCluster(expectedHash: string) {
  const actualHash = await connection.getGenesisHash();
  if (actualHash !== expectedHash) {
    throw new Error(`Connected to wrong cluster. Expected ${expectedHash}, got ${actualHash}`);
  }
  console.log('Connected to correct cluster');
}

Notlar

  1. Kümenin genesis hash’ini döndürür
  2. Genesis hash her kümeye özgüdür
  3. Hangi kümeye bağlı olduğunuzu doğrulamak için kullanılabilir
  4. Hash base-58 kodludur
  5. Mevcut durumdan okuduğu için yanıt anında gelir

En İyi Uygulamalar

  1. Küme bağlantısını doğrulamak için bu metodu kullanın
  2. RPC yükünü azaltmak için sonucu önbelleğe alın
  3. Farklı kümeler için bilinen genesis hash’leriyle karşılaştırın
  4. Diğer küme doğrulama metodlarıyla birlikte kullanın
  5. Ağ hatalarını uygun şekilde yönetin

Yaygın Hatalar

KodMesajÇözüm
-32601Method not foundBir Solana RPC düğümüne bağlı olduğunuzu doğrulayın
-32007Genesis hash unavailableDüğüm başlatılıyor veya senkronize ediliyor olabilir

Kullanım Senaryoları

  1. Küme Doğrulaması
    const CLUSTER_HASHES = {
      mainnet: '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d',
      testnet: '4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY',
      devnet: 'EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG'
    };
    
    async function verifyClusterConnection(expectedCluster: keyof typeof CLUSTER_HASHES) {
      const genesisHash = await connection.getGenesisHash();
      const expectedHash = CLUSTER_HASHES[expectedCluster];
      
      if (genesisHash !== expectedHash) {
        throw new Error(`Connected to wrong cluster. Expected ${expectedCluster} (${expectedHash}), got ${genesisHash}`);
      }
      
      return {
        cluster: expectedCluster,
        genesisHash,
        verified: true
      };
    }
    
  2. Küme Tespiti
    async function detectCluster() {
      const genesisHash = await connection.getGenesisHash();
      
      for (const [cluster, hash] of Object.entries(CLUSTER_HASHES)) {
        if (hash === genesisHash) {
          return cluster;
        }
      }
      
      throw new Error('Unknown cluster');
    }
    
  3. Ağ Yapılandırması
    interface NetworkConfig {
      cluster: string;
      genesisHash: string;
      rpcEndpoint: string;
      wsEndpoint: string;
    }
    
    async function configureNetwork(endpoint: string): Promise<NetworkConfig> {
      const connection = new Connection(endpoint);
      const genesisHash = await connection.getGenesisHash();
      const cluster = await detectCluster();
      
      return {
        cluster,
        genesisHash,
        rpcEndpoint: endpoint,
        wsEndpoint: endpoint.replace('http', 'ws')
      };
    }