Check a Robinhood network RPC endpoint with Node.js
Verify an EVM-compatible RPC endpoint's chain ID and latest block, with safe handling for common connection and JSON-RPC errors.
To check a Robinhood network RPC endpoint, obtain a provider-issued URL and the expected chain ID, then call eth_chainId and eth_blockNumber. The Node.js script below checks the chain ID before requesting the latest block. It does not assume a particular endpoint URL or chain ID.
Prepare the endpoint and expected chain ID
Start with the OnFinality Robinhood network page and consult your chosen provider's current documentation or dashboard for an endpoint and connection instructions. Confirm that the endpoint supports the EVM JSON-RPC methods used in this guide, and obtain the expected chain ID from an authoritative network source.
In a Bash session, enter the endpoint and expected hexadecimal chain ID when prompted. The endpoint input is hidden because URLs can contain credentials. Keep this terminal session open for the final step.
- Use Node.js 18 or newer, which provides the fetch API used by the script.
- Do not commit the endpoint URL or include it in issue reports if it contains an API key.
- If your provider does not document these EVM JSON-RPC methods for the endpoint, check its documented API instead of assuming the script applies.
read -r -s -p 'RPC endpoint URL: ' ROBINHOOD_RPC_URL; printf '\n'
export ROBINHOOD_RPC_URL
read -r -p 'Expected chain ID (hex, starting with 0x): ' EXPECTED_CHAIN_ID
export EXPECTED_CHAIN_IDThe expected chain ID is a network-identity check, not proof that the provider is trustworthy or that its data is current.
Create the RPC check
Save the following as check-rpc.js. It sends JSON-RPC requests with a 10-second timeout, validates each response and stops if the chain ID does not match.
- The script prints the returned chain ID and block number in hexadecimal; it does not print the endpoint URL.
- A nonzero exit status indicates a configuration, network, HTTP, JSON-RPC or response-validation failure.
const endpoint = process.env.ROBINHOOD_RPC_URL;
const expectedChainId = process.env.EXPECTED_CHAIN_ID;
const quantity = /^0x(?:0|[1-9a-fA-F][0-9a-fA-F]*)$/;
async function rpc(method, id) {
let response;
try {
response = await fetch(endpoint, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ jsonrpc: '2.0', id, method, params: [] }),
signal: AbortSignal.timeout(10_000)
});
} catch {
throw new Error(`${method}: connection failed or timed out`);
}
if (!response.ok) {
throw new Error(`${method}: HTTP ${response.status}`);
}
let body;
try {
body = await response.json();
} catch {
throw new Error(`${method}: response was not valid JSON`);
}
if (!body || body.jsonrpc !== '2.0' || body.id !== id) {
throw new Error(`${method}: invalid JSON-RPC response`);
}
if (body.error) {
const code = body.error.code;
throw new Error(`${method}: JSON-RPC error${Number.isInteger(code) ? ` ${code}` : ''}`);
}
if (typeof body.result !== 'string' || !quantity.test(body.result)) {
throw new Error(`${method}: expected a hexadecimal quantity`);
}
return body.result;
}
async function main() {
if (!endpoint || !expectedChainId || !quantity.test(expectedChainId)) {
throw new Error('Set ROBINHOOD_RPC_URL and a valid hexadecimal EXPECTED_CHAIN_ID');
}
try {
const url = new URL(endpoint);
if (!['https:', 'http:'].includes(url.protocol)) throw new Error();
} catch {
throw new Error('ROBINHOOD_RPC_URL must be an HTTP or HTTPS URL');
}
const chainId = await rpc('eth_chainId', 1);
if (BigInt(chainId) !== BigInt(expectedChainId)) {
throw new Error('Chain ID mismatch; check the endpoint and expected network');
}
const blockNumber = await rpc('eth_blockNumber', 2);
console.log(`Chain ID: ${chainId}`);
console.log(`Latest block: ${blockNumber}`);
}
main().catch((error) => {
console.error(`RPC check failed: ${error.message}`);
process.exitCode = 1;
});The script deliberately omits provider response messages and the URL from errors, reducing the risk of exposing credentials in logs.
Run the check and interpret the result
Run the script from the directory where you saved it, in the same shell session where you set the environment variables.
- On success, expect two lines: Chain ID followed by a hexadecimal value matching your expected chain ID, and Latest block followed by a hexadecimal block number. The block value changes as the network advances.
- For HTTP 401 or 403, check credentials and provider access settings. For HTTP 429, check the provider's rate-limit guidance and retry later. For a timeout, verify connectivity and the endpoint configuration.
- For a chain ID mismatch, stop and verify both the URL and the authoritative expected chain ID. For a JSON-RPC error, check whether the endpoint supports the requested method.
node check-rpc.jsA successful response shows that these two requests worked at that moment; it does not establish uptime, latency or data freshness. To investigate freshness, compare the returned block with an independent trusted network reference at approximately the same time.
RPC access reads data from a node; it is not an indexed application query. If you need to search or aggregate historical events, build and operate an indexer and query its indexed data separately. For a next step on RPC concepts and operations, browse OnFinality Learn.