Ethereum
¿Listo para usar esto en producción?
El plan gratuito cubre proyectos personales. El pago por uso escala sin necesidad de tarjeta.
Ethereum
El plan gratuito cubre proyectos personales. El pago por uso escala sin necesidad de tarjeta.
Reading blocks off Ethereum mainnet looks simple until production traffic hits it. A new block lands every 12 seconds, the head can still reorg before it's justified, and EIP-1559 means the fee floor moves every single block. Code that treats the chain as a flat, stable log of data will eventually act on a block that gets orphaned, or stall when a single RPC call times out. A systematic approach — knowing which block tag to trust, when to retry, what to cache — is what separates a demo from a service that stays correct under load.
This guide pulls together the patterns that matter across four areas: reliability (surviving flaky calls and reorgs), performance (caching and batching against chain 1's data volume), security (validating what you read before you act on it), and maintainability (structuring code so the next engineer can reason about it). Each section assumes you're talking to https://ethereum.therpc.io/YOUR_API_KEY over JSON-RPC, with WebSocket available for live subscriptions.
latest can be reorged out before it justifies. Reliability is choosing finalized (irreversible after ~12.8 minutes) for anything involving value, safe when you can tolerate a softer guarantee, and latest only for views the user can watch change. It also means every RPC call is treated as fallible — networks drop, nodes lag.latest should be polled sparingly or replaced with a newHeads subscription. Batch contiguous block reads instead of firing one request per number — Ethereum block ranges are dense and the per-call overhead dominates.parentHash chains back to what you last stored, confirm transaction receipts show status: 0x1, and never treat a pending block's contents as committed. Act on state, not on what merely appeared in the mempool.newHeads event — subscriptions can miss frames during a disconnect.finalized tag is immutable, so cache it indefinitely keyed by hash. Anything between finalized and latest can still reorg, so give it a short TTL (a slot or two, roughly 12 to 24 seconds) or skip caching it entirely.newHeads subscription for live data. Over the WebSocket endpoint wss://ethereum.therpc.io/YOUR_API_KEY, eth_subscribe('newHeads') pushes each new block the moment it's seen, so you react in near real time instead of discovering a block one poll interval late and paying for empty polls in between.parentHash equals the hash of the block you stored at the previous height. A mismatch is your earliest signal that the chain reorganized under you.latest tag. Wait for finalized, or stage the change as provisional and reconcile it if the block it depended on gets replaced. A finalized Ethereum block can't revert without a third of staked ETH being slashed, which is the guarantee worth building on.pending actually landed — confirm it by receipt and finalized inclusion.newHeads, timestamps that jump backward, a block hash that two providers disagree on at the same height, or a parentHash gap all warrant an alert. On Ethereum these usually mean a reorg or a node serving a forked view, and either should pause irreversible actions.eth_blockNumber while sitting minutes behind. Compare its head timestamp against wall clock and flag it stale if the gap exceeds a few slots, and confirm eth_chainId still returns 0x1 on every fallback path.latest and finalized widening past its usual ~2-epoch span, RPC error rate, and reorg depth are all actionable. Raw request count is noise by comparison.latest before finality? Does the reorg branch actually roll back state, or just log? Treat any value-moving action read off an unfinalized block as a change that needs justification.