Getting Reorganizations (Reorgs)
The getReorg method allows you to fetch details about blockchain reorganizations. Reorgs occur when a previously accepted chain of blocks is replaced by an alternative chain due to a higher cumulative proof of work. This method is essential for tracking and analyzing potential changes in the blockchain.
Method
getReorg(
fromBlock?: BigNumberish,
toBlock?: BigNumberish
): Promise<ReorgInformation[]>;
-
Parameters:
fromBlock?: BigNumberish: (Optional) The starting block number to query reorgs from.toBlock?: BigNumberish: (Optional) The ending block number to query reorgs until.
-
Returns:
Promise<ReorgInformation[]>: An array ofReorgInformationobjects containing details about detected reorganizations.
Object Definitions
ReorgInformation Object| Property | Type | Description |
|---|---|---|
fromBlock | string | bigint | The block number where the reorganization starts. |
toBlock | string | bigint | The block number where the reorganization ends (new chain's head). |
timestamp | number | The UNIX timestamp of when the reorganization occurred. |
Example Usage
const reorgs = await provider.getReorg(100, 200);
reorgs.forEach((reorg) => {
console.log("Reorg Start Block:", reorg.fromBlock);
console.log("Reorg End Block:", reorg.toBlock);
console.log(
"Reorg Timestamp:",
new Date(reorg.timestamp * 1000).toISOString()
);
});
Best Practices
- Ensure that the
fromBlockandtoBlockparameters are within the range of available blocks on the network. - Reorgs are rare but crucial events that can affect transaction finality and chain data integrity.
- The
timestampproperty provides the exact time of the reorganization, enabling detailed analysis.
What’s Next?
After analyzing reorg data, you can: