Parameters

This method does not take any parameters.

Response

result
string

The genesis hash as a base-58 encoded string

Code Examples

Basic Request

curl https://rpc.orbitflare.com -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getGenesisHash"
}'

Using web3.js

import { Connection } from '@solana/web3.js';

const connection = new Connection('https://rpc.orbitflare.com');

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

Notes

  1. Returns the genesis hash of the cluster
  2. The genesis hash is unique to each cluster
  3. This can be used to verify which cluster you’re connected to
  4. The hash is base-58 encoded
  5. The response is immediate as it reads from the current state

Best Practices

  1. Use this method to verify cluster connection
  2. Cache the result to reduce RPC load
  3. Compare against known genesis hashes for different clusters
  4. Use in conjunction with other cluster verification methods
  5. Handle network errors appropriately

Common Errors

CodeMessageSolution
-32601Method not foundVerify you’re connected to a Solana RPC node
-32007Genesis hash unavailableNode may be bootstrapping or syncing

Use Cases

  1. Cluster Verification

    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. Cluster Detection

    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. Network Configuration

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