This directory contains examples demonstrating the key features of the semioscan library. Examples are organized by functionality and use case.
- Semioscan Examples
Demonstrates how to calculate block ranges for specific UTC days, essential for querying blockchain data by date.
Features:
- Create
BlockWindowCalculatorfor any chain - Calculate block range for a specific UTC day
- Cache results for performance
- Integrate with other semioscan tools
Use Cases:
- Daily analytics reports
- Historical data queries
- Time-based event analysis
Run:
CHAIN_ID=42161 \
RPC_URL=https://arb1.arbitrum.io/rpc/ \
API_KEY=your_api_key \
DAY=2025-10-10 \
CACHE_PATH=block_windows.json \
cargo run --package semioscan --example daily_block_windowKey Concepts:
- Block windows map calendar dates to blockchain block ranges
- Different chains have different block production rates
- Caching saves expensive RPC calls
Demonstrates EIP-4844 blob gas calculations for L2 rollup transactions on Ethereum.
Features:
- Detect EIP-4844 (Type 3) transactions
- Calculate blob gas separately from execution gas
- Understand cost breakdown: execution + blob gas
- Analyze real-world blob transactions
Background:
- Before EIP-4844: L2 rollups posted data as expensive calldata
- After EIP-4844: L2s use cheaper "blobs" for data availability
- Cost Savings: 10-100x cheaper for L2 data posting
Use Cases:
- L2 rollup cost analysis
- Understanding L2 economics
- Transaction cost optimization
- Blob market analysis
Run:
ETHEREUM_RPC_URL=https://eth.llamarpc.com \
cargo run --package semioscan --example eip4844_blob_gasKey Concepts:
- Type 3 transactions carry data blobs
- Blob gas uses separate fee market
- Total cost = execution gas + blob gas
- Primarily used by L2 sequencers
Diagnostic probe for zkSync combined retrieval incidents. It compares the
typed eth_getTransactionByHash behavior from semioscan's
Ethereum-typed provider path with a permissive raw transaction decode and
the full combined retrieval path over the same transfer window.
Features:
- Repeated historical tx and receipt lookups for one target tx hash
- Repeated raw
eth_getTransactionByHashlookups intoAnyRpcTransaction - semioscan-backed chunked transfer scan for the matching ERC-20 window
- Full
CombinedCalculatorexecution with surfaced partial metadata - Optional alternate-provider comparison via
ZKSYNC_PROBE_ALT_RPC_URL
Use Cases:
- Investigating provider-specific zkSync transaction-shape mismatches
- Confirming whether typed tx lookups fail while raw permissive decoding succeeds
- Verifying that semioscan's combined fallback matches scanned transfer totals
- Comparing two zkSync RPC providers against the same historical tx
Run:
ZKSYNC_RPC_URL=https://your-zksync-rpc \
cargo run --package semioscan --example zksync_combined_probeKey Environment Variables:
ZKSYNC_PROBE_TX_HASH(defaults to the March 11, 2026 incident tx)ZKSYNC_PROBE_START_BLOCKZKSYNC_PROBE_END_BLOCKZKSYNC_PROBE_FROM_ADDRESSZKSYNC_PROBE_TO_ADDRESSZKSYNC_PROBE_TOKENZKSYNC_PROBE_ATTEMPTS(default:3)ZKSYNC_PROBE_DELAY_MS(default:250)ZKSYNC_PROBE_ALT_RPC_URLfor side-by-side provider comparison
Template/tutorial showing how to implement the PriceSource trait for any DEX protocol.
It compiles as an example, but it is not a turnkey production integration.
Features:
- Implement
PriceSourcefor custom DEX - Decode DEX-specific swap events
- Integrate with
PriceCalculator - Custom filtering logic
Integration Steps:
- Define your swap events using
alloy_sol_types::sol! - Implement
PriceSourcetrait:router_address(): Return DEX contract addressevent_topics(): Return event signature hashesextract_swap_from_log(): Parse events intoSwapData
- Optional: Implement
should_include_swap()for filtering - Use with
PriceCalculatorto extract prices
Example Implementations:
- Uniswap V3 integration (included in template)
- Adaptable to Curve, Balancer, SushiSwap, etc.
Run:
cargo run --package semioscan --example custom_dex_integrationKey Concepts:
PriceSourcetrait provides abstraction over DEXes- Event decoding uses alloy's type-safe sol! macro
- Filtering enables liquidator-specific analytics
Reference example data for multi-chain workflows and local experimentation. Semioscan does not automatically load this file. Defines:
- RPC endpoints per chain
- Rate limiting parameters
- Max block ranges
- Chain-specific settings
Example:
{
"chains": {
"arbitrum": {
"rpc_url": "https://arb1.arbitrum.io/rpc/",
"max_block_range": 5000,
"rate_limit_ms": 100
}
}
}-
Install Rust (latest stable):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
-
Set up environment variables:
# Create .env file in project root echo "ARBITRUM_RPC_URL=https://arb1.arbitrum.io/rpc/" >> .env echo "BASE_RPC_URL=https://mainnet.base.org" >> .env echo "ETHEREUM_RPC_URL=https://eth.llamarpc.com" >> .env
Examples require RPC access to blockchain nodes. Options:
Free Public RPCs (rate limited):
- Arbitrum:
https://arb1.arbitrum.io/rpc/ - Base:
https://mainnet.base.org - Ethereum:
https://eth.llamarpc.com
Paid RPC Providers (recommended for production):
- Alchemy: https://www.alchemy.com/
- Infura: https://www.infura.io/
- QuickNode: https://www.quicknode.com/
Note: Free RPCs have strict rate limits. For large block ranges, use paid providers.
cargo run --package semioscan --example <example_name>RPC_URL=<your_rpc_url> \
cargo run --package semioscan --example <example_name>RUST_LOG=debug \
RPC_URL=<your_rpc_url> \
cargo run --package semioscan --example <example_name>| Variable | Description | Required | Example |
|---|---|---|---|
RPC_URL |
Blockchain RPC endpoint base URL | Yes* | https://arb1.arbitrum.io/rpc/ |
API_KEY |
RPC provider API key (concatenated with RPC_URL) | No | your_alchemy_api_key |
CHAIN_ID |
Chain ID (when RPC doesn't support eth_chainId) |
Sometimes** | 42161 |
RUST_LOG |
Logging level | No | info, debug, trace |
* Some examples have defaults
** Required for chains without eth_chainId support (e.g., Avalanche)
RPC URL Construction:
When both RPC_URL and API_KEY are provided, they are concatenated using the web3-standard pattern:
// Examples concatenate base URL + API key + trailing slash
let full_url = format!("{RPC_URL}{API_KEY}/");
// e.g., "https://arb-mainnet.g.alchemy.com/v2/" + "your_key" + "/"Provider-Specific Examples:
# Alchemy (recommended pattern)
RPC_URL=https://arb-mainnet.g.alchemy.com/v2/
API_KEY=your_alchemy_api_key
# Infura
RPC_URL=https://arbitrum-mainnet.infura.io/v3/
API_KEY=your_infura_project_id
# QuickNode
RPC_URL=https://xxx-xxx-xxx.arbitrum-mainnet.quiknode.pro/
API_KEY=your_quicknode_token
# Public RPC (no API key)
RPC_URL=https://arb1.arbitrum.io/rpc/
# API_KEY not neededThis pattern matches standard web3 tooling (Hardhat, Foundry) and provider documentation.
Most public RPCs have rate limits:
- Free tier: 25-100 requests/second
- Paid tier: 300-1000+ requests/second
Semioscan automatically handles rate limiting based on chain configuration.
Large block ranges are automatically chunked:
- Default: 5,000 blocks per chunk (configurable)
- Prevents RPC timeouts
- Enables progress tracking
Examples demonstrate caching strategies:
- Block windows: Cache date→block mappings
- Gas calculations: Cache by block range
- Token discovery: Save results to JSON
Use caching to avoid re-fetching expensive blockchain data.
Error: 429 Too Many Requests
- Cause: Rate limit exceeded
- Solution: Use paid RPC provider or increase rate limit delay
Error: block range too large
- Cause: RPC doesn't support large ranges
- Solution: Reduce
max_block_rangein config (default: 5000)
Error: no logs found
- Possible causes:
- Wrong block range
- Wrong contract address
- Chain reorganization
- Solution: Verify addresses and block range
Error: chain_id not supported
- Cause: Some chains don't support
eth_chainId - Solution: Set
CHAIN_IDenvironment variable
Complete workflow for date-driven blockchain analytics on Arbitrum:
# 1. Calculate block window for specific day
CHAIN_ID=42161 \
RPC_URL=https://arb1.arbitrum.io/rpc/ \
DAY=2025-10-15 \
CACHE_PATH=block_windows.json \
cargo run --package semioscan --example daily_block_window
# 2. Feed the resulting block range into your own application
# (gas calculation, custom PriceSource scans, etc.)- Main README:
../../README.md- Library overview and API documentation - Contributing:
../../CONTRIBUTING.md- How to contribute and testing guidelines - PriceSource Guide:
../docs/PRICESOURCE_GUIDE.md- Detailed guide for implementing DEX integrations
For questions or issues:
- Open an issue on GitHub
- Check existing examples for patterns
- Review source code documentation (all examples have inline docs)
Note: These examples use blockchain-dependent code and require live RPC connections. They demonstrate production patterns from the likwid liquidation system.