Check a Solana Deadnet RPC Connection with Node.js

Send a JSON-RPC request to a configured Solana Deadnet endpoint and handle common connection and response errors.

To check whether your app can reach Solana Deadnet, send a JSON-RPC request to an endpoint you have configured. This guide uses getGenesisHash and Node.js 18 or later. Find the Solana network details on the OnFinality Solana network page, then use the endpoint provided for your access; this guide does not assume or supply an endpoint URL.

Configure your RPC endpoint

Set SOLANA_RPC_URL to the full RPC URL you received for Solana Deadnet. Keep credentials out of source code and avoid sharing the URL if it contains a secret.

  • This example sends one JSON-RPC request using the standard getGenesisHash method.
  • An RPC response checks access to a node. It does not index your program's data or provide indexed queries.
bash
export SOLANA_RPC_URL='YOUR_SOLANA_DEADNET_RPC_URL'
node rpc-check.mjs

Replace the placeholder with your configured URL before running the command.

Send the request and handle errors

Save the following as rpc-check.mjs. The script distinguishes missing configuration, HTTP failures, JSON-RPC errors, malformed responses, and network or timeout failures.

    JavaScript · Node.js
    const url = process.env.SOLANA_RPC_URL;
    
    if (!url) {
      console.error('Set SOLANA_RPC_URL to your configured Solana Deadnet RPC URL.');
      process.exit(1);
    }
    
    const controller = new AbortController();
    const timeout = setTimeout(() => controller.abort(), 15_000);
    
    try {
      const response = await fetch(url, {
        method: 'POST',
        headers: { 'content-type': 'application/json' },
        body: JSON.stringify({
          jsonrpc: '2.0',
          id: 1,
          method: 'getGenesisHash'
        }),
        signal: controller.signal
      });
    
      const body = await response.text();
      if (!response.ok) {
        console.error(`HTTP ${response.status}: ${body || response.statusText}`);
        process.exitCode = 1;
      } else {
        let data;
        try {
          data = JSON.parse(body);
        } catch {
          console.error('The endpoint returned a response that is not valid JSON.');
          process.exitCode = 1;
        }
    
        if (data) {
          if (data.error) {
            console.error('JSON-RPC error:', data.error);
            process.exitCode = 1;
          } else if (data.id !== 1 || typeof data.result !== 'string') {
            console.error('Unexpected JSON-RPC response:', data);
            process.exitCode = 1;
          } else {
            console.log('RPC request succeeded. Genesis hash:', data.result);
          }
        }
      }
    } catch (error) {
      if (error.name === 'AbortError') {
        console.error('Request timed out after 15 seconds.');
      } else {
        console.error('Could not reach the RPC endpoint:', error.message);
      }
      process.exitCode = 1;
    } finally {
      clearTimeout(timeout);
    }

    A successful response prints the genesis hash returned by the endpoint. The value depends on the endpoint and is not specified here.

    If the request fails, check that the URL is correct, credentials are valid, and your network can reach the endpoint. A timeout or error alone does not identify which cause applies.

    Know what this check tells you

    A successful getGenesisHash response confirms that this request received a valid result from the configured RPC endpoint. It does not confirm that a particular program is deployed, that its data is indexed, or that an indexing query will return records.

    For indexing and querying, you need an indexing workflow that collects and makes the relevant chain data queryable. RPC access and indexed data access are separate tasks.

    • Use RPC methods for direct requests to a Solana node.
    • Use an indexing workflow when you need to query collected chain data by the fields and filters your application requires.

    Continue with your Solana setup

    Check the OnFinality RPC Assistant for endpoint setup, or browse OnFinality Learn for developer guides. Choose the next step based on whether your app needs direct RPC calls or indexed, queryable data.