Verify a Polkadot RPC Endpoint Migration
Switch a Node.js script to a new Polkadot RPC endpoint and check that it responds for the expected chain before updating your application.
To verify a Polkadot RPC migration, point a small Node.js script at the new endpoint and call system_chain. Confirm that the returned chain name is Polkadot before directing your application’s RPC traffic to it. This checks RPC access and chain identity; it does not migrate an indexer or verify indexed data.
Choose the Polkadot RPC endpoint
Get the endpoint you intend to use and its access requirements from your provider. The Polkadot network page is a place to start when looking for network-specific information. Keep any credentials out of source code and pass the endpoint through an environment variable.
- An RPC endpoint lets an application send requests to a node.
- Indexing and querying indexed data are separate tasks. Changing an RPC endpoint does not update an indexer’s data source or move its stored data.
export POLKADOT_RPC_URL='YOUR_POLKADOT_RPC_ENDPOINT'
node --versionUse Node.js 18 or later, which provides the built-in fetch used in the next section. Replace the placeholder with the endpoint you obtained; it is not a working URL.
Check the chain returned by the endpoint
Save this as check-polkadot-rpc.mjs. It sends a JSON-RPC request for system_chain, checks the HTTP response and JSON-RPC error field, then compares the returned chain name with the expected value.
const endpoint = process.env.POLKADOT_RPC_URL;
if (!endpoint) {
console.error('Set POLKADOT_RPC_URL to your Polkadot 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: 'system_chain',
params: []
}),
signal: AbortSignal.timeout(10_000)
});
if (!response.ok) {
throw new Error(`HTTP ${response.status} ${response.statusText}`);
}
const payload = await response.json();
if (payload.error) {
throw new Error(`JSON-RPC error: ${JSON.stringify(payload.error)}`);
}
if (typeof payload.result !== 'string') {
throw new Error('Unexpected response: system_chain did not return a string.');
}
console.log(`Chain reported by endpoint: ${payload.result}`);
if (payload.result !== 'Polkadot') {
console.error('Chain name does not match the expected Polkadot network.');
process.exitCode = 1;
}
} catch (error) {
console.error(`RPC check failed: ${error.message}`);
process.exitCode = 1;
}Run it with node check-polkadot-rpc.mjs. A successful check prints Chain reported by endpoint: Polkadot and exits successfully. The actual response depends on the endpoint you supply; no live result is assumed here.
A timeout, connection or DNS error, non-success HTTP status, JSON-RPC error, or unexpected response produces an error and a nonzero exit status. If the endpoint reports another chain name, confirm that you copied the intended endpoint and network.
Apply the endpoint change to your application
After the check succeeds, update the RPC URL in your application’s configuration or secret store and deploy through your usual process. If you use a WebSocket endpoint or provider-specific authentication, make sure your application’s client configuration matches those requirements; the example above checks only an HTTP JSON-RPC endpoint.
- If your application reads chain data from an indexer, check and update that indexer’s source configuration separately. Then verify that the indexer is syncing and that its queries return the data your application expects.
- To compare candidate endpoints using your own workload, record request outcomes and elapsed times over the same period and with the same methods. Results depend on your request pattern and environment.
node check-polkadot-rpc.mjsFor further Polkadot learning material, visit OnFinality Learn. You can also review the RPC Assistant when exploring RPC options.