Choose a setup
With either failover setup, check that your route supports the methods and historical data your application needs. The examples below both call
decimals() on Ethereum mainnet WETH at the latest block. A successful eth_call returns a 32-byte hex value ending in 12, which is 18 in decimal.
Use RouteMesh for managed failover
Create an API key in the Quick start, then setROUTEMESH_API_KEY in your server environment. Ethereum mainnet uses chain ID 1.
Use viem with two RPC providers
SetETH_RPC_PRIMARY_URL and ETH_RPC_SECONDARY_URL to Ethereum mainnet URLs from two independent providers. Install viem with npm install viem, save this as failover.mjs, and run node failover.mjs.
Handle failures at the application boundary
If you use
latest, a retry may read a newer block. Pin a block number if related reads need to use the same block height. For requests that still fail, record the RPC method, HTTP status, JSON-RPC error, and RouteMesh’s X-Batch-Id header when present. See Debugging.
Transaction writes
A timeout oneth_sendRawTransaction can occur after an upstream accepts the signed transaction. Compute and retain the transaction hash before sending, then check it with eth_getTransactionByHash or eth_getTransactionReceipt if the outcome is unclear. An empty response from one provider can mean the transaction has yet to propagate there. If your application decides to rebroadcast, use the same signed bytes and preserve any private submission policy.
WebSocket subscriptions
While your client socket stays open, RouteMesh can switch upstream providers and replay missed notifications. If the client socket disconnects, reconnect and re-subscribe. For log subscriptions, track the last processed block, backfill missed events witheth_getLogs, and deduplicate overlapping events. See the WebSocket API.
Benchmark results
In RouteMesh’s controlled Ethereumeth_call benchmark, the simulated primary returned HTTP 429 or 502 and the simulated backup returned a valid response. Sequential failover and RouteMesh routing each completed 100 of 100 reads under each error condition. The single-upstream configuration completed 0 of 100 under each condition.
The benchmark page publishes the test setup, latency percentiles, and observed production outcomes with sample counts. The production table covers Ethereum eth_call requests whose first recorded upstream response was HTTP 429 or 502. RPC failover benchmark
