getGenesisHash
Learn getGenesisHash use cases, code examples, request parameters, response structure, and tips.
The getGenesisHash
RPC method returns the genesis hash of the Solana cluster to which the queried node is connected. This hash uniquely identifies the specific network—such as Mainnet Beta, Devnet, Testnet, or a custom/private cluster.
✅ Common Use Cases
Verify Connected Network Ensure your application is interacting with the intended cluster (e.g., Devnet vs. Mainnet Beta) by comparing the genesis hash.
Client Configuration Use the genesis hash programmatically to conditionally configure tools, wallets, or front-end applications based on the connected cluster.
Prevent Cross-Cluster Caching Errors Incorporate the genesis hash into cache keys to avoid serving data from one network on another—important when working with multiple environments.
🛠Request Parameters
This method does not accept any parameters.
📦 Response Structure
The response includes:
{
"jsonrpc": "2.0",
"result": "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"id": 1
}
result
(string):
The base-58 encoded genesis hash of the connected cluster.
💡 Example: Fetch the Genesis Hash
{
"jsonrpc": "2.0",
"id": 1,
"method": "getGenesisHash"
}
Code Examples
const fetch = require('node-fetch');
async function getGenesisHash(rpcUrl) {
try {
const response = await fetch(rpcUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getGenesisHash'
}),
});
const data = await response.json();
// Print the exact full response
console.log('Full RPC Response:');
console.log(JSON.stringify(data, null, 2));
return data;
} catch (error) {
console.error('Error getting health:', error.message);
return null;
}
}
// Example usage
const RPC_URL = 'https://rpc.coinvera.io/?x-api-key=your-coinvera-x-api-key';
getGenesisHash(RPC_URL);
Example Response
{
"jsonrpc": "2.0",
"result": "5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d",
"id": 1
}
🧠Developer Tips
Unique Per Cluster Each Solana network has its own unique genesis hash. For example:
Mainnet Beta:
5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp
Devnet/Testnet: Different and distinct hashes
Private clusters: Will have custom genesis hashes
Immutable Identifier The genesis hash is set once at cluster initialization and never changes.
Recommended Safety Check For sensitive actions (e.g., sending real funds), applications should verify that the returned hash matches the expected cluster hash to avoid misrouting operations.
Last updated