GetGenesisHash
Returns the genesis hash of the cluster the node belongs to. The genesis hash uniquely identifies a Solana cluster (mainnet-beta, testnet, devnet, or a local validator). This is the gRPC equivalent of the JSON-RPC getGenesisHash method.
Use this method to verify that your client is connected to the correct cluster before executing transactions. This is a critical safety check for production trading systems that must never accidentally send mainnet transactions to devnet or vice versa.
Type: Unary (request/response)
Parameters
This method takes no parameters.
Response
| Field | Type | Description |
|---|---|---|
hash | string | The genesis hash as a base-58 encoded string |
Code Examples
Node.js
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const packageDef = protoLoader.loadSync('geyser.proto', {
keepCase: true, longs: String, enums: String, defaults: true, oneofs: true
});
const proto = grpc.loadPackageDefinition(packageDef).geyser;
const client = new proto.Geyser('88.216.36.108:10001', grpc.credentials.createInsecure());
client.getGenesisHash({}, (err, response) => {
if (err) { console.error('gRPC error:', err); return; }
console.log('Genesis hash:', response.hash);
// Mainnet-beta genesis hash for verification
const MAINNET_GENESIS = '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d';
if (response.hash === MAINNET_GENESIS) {
console.log('Connected to mainnet-beta');
} else {
console.log('Connected to a non-mainnet cluster');
}
});Rust
use yellowstone_grpc_client::GeyserGrpcClient;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let mut client = GeyserGrpcClient::build_from_uri("http://88.216.36.108:10001")
.connect()
.await?;
let response = client.get_genesis_hash().await?;
let genesis = response.into_inner();
println!("Genesis hash: {}", genesis.hash);
// Verify mainnet-beta
const MAINNET_GENESIS: &str = "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d";
if genesis.hash == MAINNET_GENESIS {
println!("Confirmed: connected to mainnet-beta");
}
Ok(())
}Example Response
{
"hash": "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d"
}