Verify a Sui Node Provider with a JSON-RPC Request

Check that a Sui RPC endpoint responds, identify its chain, and handle common request failures with Node.js.

To verify a Sui node provider, send a JSON-RPC request to its endpoint and check both the HTTP response and the JSON-RPC result. The Node.js script below calls sui_getChainIdentifier, prints the returned identifier, and exits with a nonzero status if the request fails. You can obtain an endpoint through the OnFinality Sui network page; use the endpoint and credentials supplied for your own access rather than inventing a URL.

Prepare the endpoint

Use Node.js 18 or later, which includes the fetch API used by this example. Set SUI_RPC_URL to the complete HTTPS endpoint supplied by your provider, including any credential required in the URL.

Treat the endpoint as a secret if it contains credentials: avoid committing it to source control or sharing terminal history and logs. This example assumes URL-based access; if your provider requires an authorization header instead, add it according to its instructions.

    bash
    export SUI_RPC_URL='YOUR_PROVIDER_ENDPOINT'
    node --version

    Replace the placeholder with your actual endpoint. Confirm that the displayed Node.js major version is 18 or higher.

    Request the chain identifier

    Save the following as check-sui-rpc.js and run it with node check-sui-rpc.js. The script applies a 10-second timeout, checks the HTTP status, and rejects JSON-RPC errors or an unexpected result.

      JavaScript · Node.js
      const endpoint = process.env.SUI_RPC_URL;
      
      async function main() {
        if (!endpoint) throw new Error('Set SUI_RPC_URL before running this script.');
      
        const controller = new AbortController();
        const timer = setTimeout(() => controller.abort(), 10_000);
      
        try {
          const response = await fetch(endpoint, {
            method: 'POST',
            headers: { 'content-type': 'application/json' },
            body: JSON.stringify({
              jsonrpc: '2.0',
              id: 1,
              method: 'sui_getChainIdentifier',
              params: []
            }),
            signal: controller.signal
          });
      
          if (!response.ok) throw new Error(`HTTP ${response.status}`);
          const body = await response.json();
          if (body.error) throw new Error(`JSON-RPC error ${body.error.code}: ${body.error.message}`);
          if (body.jsonrpc !== '2.0' || body.id !== 1 || typeof body.result !== 'string' || !body.result) {
            throw new Error('Unexpected JSON-RPC response.');
          }
          console.log(`Sui chain identifier: ${body.result}`);
        } finally {
          clearTimeout(timer);
        }
      }
      
      main().catch((error) => {
        const message = error.name === 'AbortError' ? 'Request timed out.' : error.message;
        console.error(`Sui RPC check failed: ${message}`);
        process.exitCode = 1;
      });

      On success, expect a line beginning Sui chain identifier: followed by a nonempty identifier. Compare it with a trusted identifier for your intended network; a successful response alone does not prove you selected the right network.

      Interpret failures and next steps

      A timeout or network error warrants checking connectivity and the endpoint configuration. For HTTP 401 or 403, check credentials and access settings; for HTTP 429, check your provider's rate-limit guidance and retry policy. A JSON-RPC error can indicate a rejected or unsupported request; inspect its code and message without exposing secrets.

      This check verifies one RPC response, not reliability, latency, or historical-data availability. If those matter to your application, measure repeated requests and test the specific methods and data ranges you need.

      RPC access lets an application request data from a node; indexing processes blockchain data into a queryable store suited to application-specific lookups. A successful RPC check does not create an index or establish that an indexing query will work. For a next step in exploring RPC requests, use the OnFinality RPC Assistant.