Production starter
Make a server-side RPC call, read contract events, and handle NodeFlare limits without exposing your key.
Create a free API key, choose a supported chain, and keep the key in your backend environment. A public frontend bundle is not a safe place for an API key.
Read from your backend
This Node.js example uses built-in fetch. Set NODEFLARE_API_KEY in your server environment. It reads the current Ethereum block and fails clearly on HTTP and JSON-RPC errors.
const key = process.env.NODEFLARE_API_KEY;
if (!key) throw new Error("Set NODEFLARE_API_KEY on the server");
const endpoint = `https://rpc.nodeflare.app/eth/v1/${key}`;
async function rpc(method, params = []) {
const response = await fetch(endpoint, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method, params }),
signal: AbortSignal.timeout(10000),
});
if (response.status === 429) throw new Error("Rate or quota limit: check your dashboard before retrying");
if (!response.ok) throw new Error(`RPC HTTP ${response.status}`);
const body = await response.json();
if (body.error) throw new Error(`RPC error ${body.error.code}: ${body.error.message}`);
return body.result;
}
const latest = await rpc("eth_blockNumber");
console.log("Current block:", Number(BigInt(latest)));Read a bounded range of contract events
Continue with the same rpc function. Use your own deployed contract address, an explicit block range and relevant event topics. Supported ranges depend on the chain and query shape; see getLogs limits.
const contract = process.env.CONTRACT_ADDRESS;
if (!/^0x[0-9a-fA-F]{40}$/.test(contract ?? "")) {
throw new Error("Set a valid CONTRACT_ADDRESS for Ethereum");
}
const head = Number(BigInt(await rpc("eth_blockNumber")));
const events = await rpc("eth_getLogs", [{
address: contract,
fromBlock: `0x${Math.max(0, head - 20).toString(16)}`,
toBlock: `0x${head.toString(16)}`,
}]);
console.log("Recent matching logs:", events.length);Recent blocks can reorganize. Production indexers need a confirmation policy, block-hash checks, replay and durable checkpoints. This short example is a connectivity check, not a complete indexer.
Before production
- Confirm the chain's method support and historical availability.
- Bound concurrent calls and retry temporary errors with backoff. Never retry indefinitely.
- Distinguish rate limits from exhausted monthly quota; repeated retries do not refill a quota.
- Measure your own latency and error rate using a representative workload.
- Keep a rollback configuration and monitor the status page.
Compare plan capacity, inspect the benchmark method, or ask the operators to scope a migration.