Verify an Arbitrum RPC Endpoint with Node.js
Check that an Arbitrum endpoint accepts JSON-RPC requests and reports the expected chain before using it in an application.
To verify an Arbitrum One RPC endpoint, call eth_chainId and compare the result with 0xa4b1 (42161). Then call eth_blockNumber to confirm the endpoint can return a current block. This checks RPC access; it does not index blockchain data or provide an indexing query interface.
Get an endpoint and set it locally
Choose an endpoint for Arbitrum from the Arbitrum network page or use an endpoint you already have access to. Copy its URL into an environment variable; do not commit credentials or private endpoint URLs to source control.
- This guide targets Arbitrum One, whose chain ID is
42161(0xa4b1). - An RPC endpoint lets an application request node data. Indexing and querying transformed or application-specific data require an indexing workflow.
export ARBITRUM_RPC_URL='YOUR_ARBITRUM_RPC_URL'Replace the placeholder with the endpoint URL you obtained. The command stores it only in the current shell session.
Check chain ID and current block
Run this with Node.js 18 or later. The script rejects missing configuration, HTTP failures, JSON-RPC errors, invalid responses, and a chain ID that does not match Arbitrum One.
- The block number is read from the endpoint at runtime, so it will vary.
- A successful response confirms these two RPC methods worked for this request; it does not measure latency, guarantee future availability, or validate every method your application needs.
const url = process.env.ARBITRUM_RPC_URL;
if (!url) {
console.error('Set ARBITRUM_RPC_URL to your Arbitrum RPC endpoint.');
process.exit(1);
}
const expectedChainId = '0xa4b1';
let requestId = 0;
async function rpc(method) {
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), 10_000);
try {
const response = await fetch(url, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ jsonrpc: '2.0', id: ++requestId, method, params: [] }),
signal: controller.signal,
});
if (!response.ok) throw new Error(`HTTP ${response.status} ${response.statusText}`);
const body = await response.json();
if (body.error) throw new Error(`JSON-RPC ${body.error.code}: ${body.error.message}`);
if (body.jsonrpc !== '2.0' || body.result === undefined) {
throw new Error('Malformed JSON-RPC response');
}
return body.result;
} finally {
clearTimeout(timer);
}
}
try {
const chainId = await rpc('eth_chainId');
if (chainId.toLowerCase() !== expectedChainId) {
throw new Error(`Unexpected chain ID ${chainId}; expected ${expectedChainId} (Arbitrum One)`);
}
const blockNumber = await rpc('eth_blockNumber');
if (typeof blockNumber !== 'string' || !/^0x[0-9a-f]+$/i.test(blockNumber)) {
throw new Error('Invalid eth_blockNumber result');
}
console.log(JSON.stringify({ ok: true, chainId, blockNumber }, null, 2));
} catch (error) {
const message = error.name === 'AbortError' ? 'Request timed out after 10 seconds' : error.message;
console.error(`Arbitrum RPC check failed: ${message}`);
process.exitCode = 1;
}Save the script as check-arbitrum.mjs and run node check-arbitrum.mjs. A successful response has ok: true, chainId: "0xa4b1", and a hexadecimal blockNumber returned by the endpoint. If it fails, check the URL, network access, endpoint credentials, and whether the endpoint serves Arbitrum One.
Choose RPC access or indexing
Use the endpoint for direct JSON-RPC calls such as reading blocks or submitting transactions. If your application needs indexed data and query capabilities, choose an indexing workflow instead of treating an RPC URL as an indexer.
For more guides, visit OnFinality Learn. To explore endpoint options, visit the RPC Assistant.