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
1const grpc = require('@grpc/grpc-js');
2const protoLoader = require('@grpc/proto-loader');
3
4const packageDef = protoLoader.loadSync('geyser.proto', {
5 keepCase: true, longs: String, enums: String, defaults: true, oneofs: true
6});
7const proto = grpc.loadPackageDefinition(packageDef).geyser;
8const client = new proto.Geyser('[IP_ADDRESS]:[PORT]', grpc.credentials.createInsecure());
9
10client.getGenesisHash({}, (err, response) => {
11 if (err) { console.error('gRPC error:', err); return; }
12 console.log('Genesis hash:', response.hash);
13
14 // Mainnet-beta genesis hash for verification
15 const MAINNET_GENESIS = '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d';
16 if (response.hash === MAINNET_GENESIS) {
17 console.log('Connected to mainnet-beta');
18 } else {
19 console.log('Connected to a non-mainnet cluster');
20 }
21});Rust
1use yellowstone_grpc_client::GeyserGrpcClient;
2
3#[tokio::main]
4async fn main() -> anyhow::Result<()> {
5 let mut client = GeyserGrpcClient::build_from_uri("http://[IP_ADDRESS]:[PORT]")
6 .connect()
7 .await?;
8
9 let response = client.get_genesis_hash().await?;
10 let genesis = response.into_inner();
11 println!("Genesis hash: {}", genesis.hash);
12
13 // Verify mainnet-beta
14 const MAINNET_GENESIS: &str = "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d";
15 if genesis.hash == MAINNET_GENESIS {
16 println!("Confirmed: connected to mainnet-beta");
17 }
18
19 Ok(())
20}Example Response
1{
2 "hash": "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d"
3}