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.
A chain reorganization is the moment Ethereum decides that a block your app already saw was the wrong one. The canonical chain switches to a competing branch, and one or more blocks at the head get dropped and replaced. On post-Merge Ethereum these are almost always shallow — a single block at the tip, reorged out before it was justified. They happen because two validators' views briefly disagree across a 12-second slot, usually from propagation latency, and the fork-choice rule then settles on one branch.
The crucial nuance for chain 1 is finality. Short head reorgs are possible before a block justifies, but once a block reaches the finalized tag, reverting it would force the protocol to slash a third of the validator set's stake — so deep reorgs of finalized history simply don't happen. The danger zone is the unfinalized tail. If your app credited a deposit, fired a webhook, or updated a balance off a block at latest that then gets reorged away, your state now reflects a transaction that no longer exists on the canonical chain. Handling that gap is what this guide is about.
latest, not a Bitcoin-style multi-block rewrite of settled history.latest can become stale; only inclusion at or below finalized is safe to treat as permanent.parentHash mismatch: when a new head's parentHash no longer matches the recorded hash one block below it, or the hash at a height you already saved has since changed, the chain reorganized. Watching newHeads and re-checking finalized vs. latest gives you the same signal in near real time.finalized tag as your bar: a block at or below the finalized height (about two epochs, ~12.8 minutes back) won't reorg. For lower-stakes flows the safe tag is a reasonable middle ground. Whatever you read at latest, assume it can still vanish.parentHash against the previous stored hash. In a subscription model, do the same on every newHeads push. Either way, the mismatch is your reorg trigger; subscriptions just catch it a slot sooner.newHeads subscription over wss://ethereum.therpc.io/YOUR_API_KEY gives you the fastest reorg signal and the lowest cost. Keep a slower polling loop as a backstop, since a dropped WebSocket can miss the exact block where the reorg happened — the poller re-derives it from stored hashes on reconnect.