Read a Bittensor Subnet’s Tempo Through RPC

Use a Substrate-compatible RPC endpoint and the Polkadot.js API to read the current tempo for a Bittensor subnet.

Use the Bittensor RPC endpoint you have access to, pass a subnet ID, and read subtensorModule.subnetTempo from the chain’s current runtime state. The Bittensor network page is a useful place to begin when selecting an endpoint; this guide does not assume a particular provider URL or availability.

Read the current tempo

Install the client library with npm install @polkadot/api, set RPC_URL to your own HTTP or WebSocket RPC URL, and set NETUID to the subnet ID you want to inspect. The query is made against the latest state visible through that RPC connection.

  • A subnet tempo is returned as a chain value, so convert it to a string before serialising it.
  • The block number in the output identifies the latest block observed when the request completed.
JavaScript · Node.js
import { ApiPromise, HttpProvider, WsProvider } from '@polkadot/api';

const endpoint = process.env.RPC_URL;
const netuidText = process.env.NETUID;

if (!endpoint) {
  console.error('Missing RPC_URL. Set it to an HTTP or WebSocket RPC endpoint.');
  process.exit(1);
}

if (!netuidText || !/^\\d+$/.test(netuidText)) {
  console.error('Missing or invalid NETUID. Set it to a non-negative integer.');
  process.exit(1);
}

const netuid = Number(netuidText);
let api;

try {
  const provider = /^https?:\\/\\//i.test(endpoint)
    ? new HttpProvider(endpoint)
    : new WsProvider(endpoint);

  api = await ApiPromise.create({ provider });

  const tempoQuery = api.query?.subtensorModule?.subnetTempo;
  if (typeof tempoQuery !== 'function') {
    throw new Error('The connected runtime does not expose subtensorModule.subnetTempo in its metadata.');
  }

  const [header, tempo] = await Promise.all([
    api.rpc.chain.getHeader(),
    tempoQuery(netuid)
  ]);

  console.log(JSON.stringify({
    netuid,
    block: header.number.toString(),
    subnetTempo: tempo.toString()
  }, null, 2));
} catch (error) {
  console.error(`RPC read failed: ${error.message}`);
  process.exitCode = 1;
} finally {
  if (api) await api.disconnect();
}

Run it with RPC_URL='your-endpoint' NETUID=1 node read-tempo.mjs.

Expected result: a JSON object containing the supplied netuid, a decimal block value, and the returned subnetTempo value. The numbers will depend on the endpoint, subnet, and request time.

Interpret the value without guessing

Tempo is returned by the runtime storage query for the selected subnet. Treat the value as chain data rather than as a locally measured duration; use the network’s documented unit and runtime semantics when converting it into application behaviour.

The result is a point-in-time read. Repeating the request can produce a different block number or tempo if the subnet configuration changes.

  • Validate the subnet ID in your application before displaying or storing the result.
  • If you need a reproducible observation, record the block number together with the tempo and repeat the read at a defined interval.

Handle RPC and runtime failures

An invalid URL, an unavailable endpoint, a rejected request, or a transport timeout will be reported as an RPC read failure and the script exits with a nonzero status. This makes it suitable for a scheduled check or a deployment health step without silently treating an error as a tempo value.

A successful connection can still fail the query when the connected runtime metadata does not expose the expected pallet or method. That usually means the endpoint is not serving the intended Bittensor runtime, or the runtime API has changed; inspect the endpoint and metadata instead of substituting a guessed storage key.

  • Keep credentials out of source code and provide them through RPC_URL or your runtime’s secret configuration.
  • For production code, add a request timeout and bounded retries around the connection and query, while preserving the nonzero failure path.

Know when RPC is not enough

This example performs a live RPC read; it does not index blocks, retain historical tempo changes, or provide a queryable dataset across many subnets. An RPC endpoint answers requests against chain state, while an indexer consumes chain data and exposes application-oriented historical queries.

Use the direct read for current configuration checks. If your application needs history, filtering, joins, or dashboards, design an indexing pipeline and query layer separately. The OnFinality Learn library contains broader indexing guidance, and RPC Assistant can help you work out RPC requests without assuming an endpoint in this guide.

  • Measure your own latency, error rate, and retry behaviour from the environment where your application runs; this guide makes no performance claim about any endpoint.
  • Keep the RPC read and any historical index as separate data paths so a missing index does not get mistaken for missing current chain state.