Skip to content

Conversation

@alphafitz11
Copy link
Collaborator

πŸ“¦ Add Block Finder Tool

Description

Added a command-line tool to quickly find blocks by timestamp with multi-chain support.

Key Features

  • βœ… Binary Search Algorithm: Efficiently finds the closest block after a given timestamp
  • βœ… Multi-chain Support: Supports ETH, BSC, Arbitrum, Base, OP, Polygon, and other major chains
  • βœ… Smart Timestamp Handling: Automatically detects and converts millisecond timestamps
  • βœ… Estimation Optimization: Estimates search range using average block time to reduce queries
  • βœ… Detailed Logging: Outputs search progress and iteration details for debugging

Usage

node findBlock.js <chain> <timestamp>

# Examples
node findBlock.js eth 1704067200
node findBlock.js bsc 1704067200

Configuration

Requires RPC URLs configured in .env file at project root:

ETH_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY
BSC_RPC_URL=https://bsc-dataseed.binance.org/
ARB_RPC_URL=https://arb1.arbitrum.io/rpc

Technical Implementation

  • Uses ethers.js for blockchain interaction
  • Binary search algorithm with O(log n) average search complexity
  • Intelligently estimates search range based on average block time from the latest 100 blocks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants