Diagnose a Bittensor RPC timeout with a header request

Use a small Node.js probe to separate endpoint timeouts from JSON-RPC errors and indexing or query-layer problems.

Start by sending a lightweight chain_getHeader request to the Bittensor RPC endpoint configured in BITTENSOR_RPC_URL. The probe below applies a finite timeout, reports HTTP and JSON-RPC failures separately, and avoids treating an indexing problem as an RPC timeout. For endpoint configuration, begin with the Bittensor network page.

Run a bounded JSON-RPC request

This checks whether the endpoint accepts a standard Substrate JSON-RPC request and returns a chain header. It does not query an indexer, GraphQL API, archive dataset, or application-specific service.

Save the script as check-bittensor-rpc.mjs, then run it with Node.js 18 or newer after setting the endpoint supplied by your RPC configuration.

  • The endpoint is deliberately read from an environment variable rather than embedded in the guide.
  • A timeout is a client-observed lack of response within the chosen limit, not proof that the network or chain is unavailable.
JavaScript · Node.js
const endpoint = process.env.BITTENSOR_RPC_URL;
const timeoutMs = Number(process.env.RPC_TIMEOUT_MS || 10000);

if (!endpoint) {
  console.error("Set BITTENSOR_RPC_URL to your Bittensor JSON-RPC endpoint.");
  process.exit(1);
}

let parsed;
try {
  parsed = new URL(endpoint);
  if (!["http:", "https:"].includes(parsed.protocol)) throw new Error("unsupported protocol");
} catch {
  console.error("BITTENSOR_RPC_URL must be an http or https URL.");
  process.exit(1);
}

const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), timeoutMs);
const request = {
  jsonrpc: "2.0",
  id: 1,
  method: "chain_getHeader",
  params: []
};

try {
  const response = await fetch(parsed, {
    method: "POST",
    headers: { "content-type": "application/json" },
    body: JSON.stringify(request),
    signal: controller.signal
  });
  const raw = await response.text();
  let body;
  try {
    body = JSON.parse(raw);
  } catch {
    throw new Error(`HTTP ${response.status}: response was not JSON`);
  }

  if (!response.ok) {
    throw new Error(`HTTP ${response.status}: ${JSON.stringify(body)}`);
  }
  if (body.error) {
    throw new Error(`JSON-RPC error ${body.error.code}: ${body.error.message}`);
  }
  if (!body.result) {
    throw new Error("JSON-RPC response did not contain a result");
  }

  console.log("RPC OK");
  console.log(JSON.stringify(body, null, 2));
} catch (error) {
  if (error.name === "AbortError") {
    console.error(`RPC timeout after ${timeoutMs} ms: no response was received.`);
    process.exitCode = 2;
  } else {
    console.error(`RPC check failed: ${error.message}`);
    process.exitCode = 1;
  }
} finally {
  clearTimeout(timer);
}

Run it with BITTENSOR_RPC_URL="https://your-configured-endpoint" node check-bittensor-rpc.mjs. Replace the placeholder with the endpoint from your own configuration; do not copy it literally.

A successful run prints RPC OK followed by a JSON-RPC response whose result contains the returned header fields, such as the chain's current header data. The exact values depend on when you run the check.

Exit code 2 means the local deadline expired. Exit code 1 means configuration, transport, HTTP, malformed-response, or JSON-RPC validation failed.

Classify the failure before changing code

If the probe returns a header, basic RPC access is working from that machine. A timeout in a separate application may instead come from a longer-running method, an overloaded client, a proxy deadline, connection-pool exhaustion, or a timeout in the application itself.

If the probe times out, repeat it from the same runtime and network as the failing application, record the timestamp and configured timeout, and inspect the endpoint's HTTP or gateway logs when available. Do not respond by adding unlimited retries; use a bounded retry policy with backoff and preserve the original error context.

  • An HTTP status such as 401, 403, or 429 is an HTTP access or policy result, not a JSON-RPC timeout.
  • A JSON-RPC error proves that a response arrived; investigate the method, parameters, permissions, or node support rather than only increasing the timeout.
  • A successful header request does not prove that every RPC method, subscription, or historical query will succeed.

Check whether the problem is actually indexing or querying

RPC access exposes node methods such as chain_getHeader. Indexing and querying are separate layers that transform or store chain data for application queries. A GraphQL query timeout, missing entity, stale indexed block, or failed mapping is not automatically a Bittensor RPC timeout.

To isolate the layer, compare three observations: the direct header probe, the indexer's latest processed block or health status, and the application query that failed. If the direct probe succeeds while the indexer lags or the query fails, debug the indexer, mapping, query shape, or data availability instead of retrying the RPC call.

  • Log the RPC method, request identifier, start time, end time, HTTP status, and sanitized error message.
  • Never log API keys or authorization headers when capturing diagnostics.
  • Measure your own latency and timeout rate from the deployment environment; this guide does not assume a benchmark or service-level result.

Choose the next diagnostic step

Once the direct request works, test the exact RPC method used by your application with a small, known-safe parameter set and the same timeout budget. If only that method fails, inspect its parameters and node compatibility.

For broader Bittensor RPC configuration guidance, continue with the OnFinality RPC Assistant. You can also browse the OnFinality Learn library for related RPC and indexing workflows.

  • Keep the header probe as a deployment smoke test, but do not use it as an indexing health check.
  • If a provider or gateway is involved, compare its documented request limits with your method and payload rather than assuming all RPC calls have the same behavior.