Parameters
This method does not take any parameters.
Response
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
- Returns the genesis hash of the cluster
- The genesis hash is unique to each cluster
- This can be used to verify which cluster you’re connected to
- The hash is base-58 encoded
- The response is immediate as it reads from the current state
Best Practices
- Use this method to verify cluster connection
- Cache the result to reduce RPC load
- Compare against known genesis hashes for different clusters
- Use in conjunction with other cluster verification methods
- Handle network errors appropriately
Common Errors
Code | Message | Solution |
---|
-32601 | Method not found | Verify you’re connected to a Solana RPC node |
-32007 | Genesis hash unavailable | Node may be bootstrapping or syncing |
Use Cases
-
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
};
}
-
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');
}
-
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')
};
}