Check an OP Node’s Sync Status from Node.js

Call an op-node RPC method from Node.js to inspect rollup sync status, handle common errors, and distinguish node RPC access from indexed data queries.

To check whether an OP Stack node is catching up, call optimism_syncStatus on the op-node RPC endpoint and inspect the returned status fields. This guide uses a URL you provide at runtime; it does not assume a public endpoint or a particular sync state.

Prepare an op-node RPC URL

Use the RPC URL configured for your op-node. The method in this example is an op-node rollup RPC method; it is not an Ethereum execution JSON-RPC method such as eth_blockNumber. Keep credentials out of source control and pass the URL through an environment variable.

  • You need Node.js 18 or later and access to an op-node RPC endpoint.
  • This checks the response from one configured endpoint; it does not establish a live network-wide status.
bash
export OP_NODE_RPC_URL='http://127.0.0.1:9545'

Replace the example local address with the endpoint configured for your node. No provider endpoint is implied.

Request the sync status

Save the following as check-op-node.mjs, then run it with OP_NODE_RPC_URL set. The script sends a JSON-RPC request with no parameters and prints the returned result. It exits with a nonzero status for a missing URL, HTTP or network failure, invalid JSON, a JSON-RPC error, or a response without a result.

    JavaScript · Node.js
    const endpoint = process.env.OP_NODE_RPC_URL;
    
    if (!endpoint) {
      console.error('Set OP_NODE_RPC_URL to your op-node RPC endpoint.');
      process.exit(1);
    }
    
    try {
      const response = await fetch(endpoint, {
        method: 'POST',
        headers: { 'content-type': 'application/json' },
        body: JSON.stringify({
          jsonrpc: '2.0',
          id: 1,
          method: 'optimism_syncStatus',
          params: [],
        }),
        signal: AbortSignal.timeout(10_000),
      });
    
      const body = await response.json().catch(() => {
        throw new Error(`Endpoint returned non-JSON content (HTTP ${response.status}).`);
      });
    
      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 (!Object.hasOwn(body, 'result')) {
        throw new Error('JSON-RPC response has no result field.');
      }
    
      console.log(JSON.stringify(body.result, null, 2));
    } catch (error) {
      console.error(`Could not read op-node sync status: ${error.message}`);
      process.exitCode = 1;
    }

    Run node check-op-node.mjs. On success, the expected result is a JSON object containing the sync status fields returned by that op-node. Field values depend on the node at the time of the request; this example does not predict them.

    If the call fails, check that the URL points to the op-node RPC listener, that the listener is reachable from this machine, and that the method is available in the node’s configured RPC interface.

    Know what this check tells you

    optimism_syncStatus provides the op-node’s reported rollup sync status. Read its returned fields against your node’s configuration and the OP Stack documentation for the version you run; the response itself is the evidence for this check.

    Successful RPC access is not the same as indexing or querying indexed data. An RPC call requests data or status from a node. An indexer processes chain data into a queryable store, which a query API then serves. Use an indexer when your task requires application-specific, historical, or structured queries beyond the RPC methods available from your node.

    • A timeout or connection error indicates this request did not get a usable response; it does not by itself identify whether the cause is the node, network path, or endpoint configuration.
    • To track changes, run the request at intervals and record timestamps and returned fields. Measure the behavior in your own environment rather than assuming a sync rate.

    Continue with the right tool

    For broader context on OP Stack node clients, see OP Stack node clients: op-node, op-geth, op-reth, and Superchain. For RPC concepts and endpoint setup, use the OnFinality RPC Assistant. The OnFinality Learn library has additional developer guides.