Verify Which Solana Cluster an RPC Endpoint Reaches
Use Solana JSON-RPC to identify an endpoint’s cluster before sending development requests to it.
To check which Solana cluster an RPC endpoint reaches, call its getGenesisHash method and compare the returned hash with a trusted reference for the cluster you intend to use. This guide uses Solana Devnet. The OnFinality Solana network page is one place to find network-specific information.
Choose the cluster endpoint
For this example, use Solana’s public Devnet RPC URL, https://api.devnet.solana.com. Solana also documents its clusters and public RPC endpoints. Put the URL in an environment variable so you can switch clusters without editing the script.
- A successful RPC response tells you the endpoint answered the request; the genesis hash helps identify the cluster.
- Public endpoints may have usage limits. Handle request failures and consult the endpoint’s documentation if you need access details.
Request the genesis hash with Node.js
Save this as check-cluster.mjs and run it with Node.js 18 or newer. The script checks the HTTP response, parses JSON, and reports JSON-RPC errors or a missing result instead of treating them as a successful cluster check.
const endpoint = process.env.SOLANA_RPC_URL ?? "https://api.devnet.solana.com";
try {
const response = await fetch(endpoint, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "getGenesisHash",
params: [],
}),
signal: AbortSignal.timeout(10_000),
});
if (!response.ok) {
throw new Error(`HTTP ${response.status} ${response.statusText}`);
}
const data = await response.json();
if (data.error) {
throw new Error(`JSON-RPC error: ${JSON.stringify(data.error)}`);
}
if (typeof data.result !== "string" || data.result.length === 0) {
throw new Error("Response did not contain a genesis hash");
}
console.log(`Endpoint: ${endpoint}`);
console.log(`Genesis hash: ${data.result}`);
} catch (error) {
console.error(`Cluster check failed: ${error.message}`);
process.exitCode = 1;
}Run node check-cluster.mjs. To check another cluster, set SOLANA_RPC_URL to an endpoint documented for that cluster, then run the script again. A successful run prints the endpoint and the hash returned by that endpoint; the hash value depends on the response and is not fixed here.
Compare the returned hash with a trusted cluster reference before relying on the endpoint for a particular environment. A timeout, HTTP error, JSON-RPC error, or missing result means the check did not establish the cluster.
Keep RPC checks distinct from indexing
This request checks an RPC endpoint and reads one value from the Solana network. It does not index account or program activity, store historical data, or provide a query layer for an application. If your task needs indexed data, identify an indexing service and confirm its supported networks and query interface separately.
For further setup guidance, continue with OnFinality Learn or explore the OnFinality RPC Assistant.