Overview
The full code for this starter implementation can be found here. The guide below explains the core components, how it works, and what parts you may need to customize to your needs. The sample is a Bun + TypeScript project that usesviem
for interacting with Base Chain via standard Ethereum JSON-RPC methods. It also utilizes Uniswap’s SDKs to make some calculations easier.
Core Components
1. Event Monitoring (index.ts
)
The main entry point scans Uniswap V4 Initialize
events within a specified block range to discover newly created pools.
- Uses
publicClient.getContractEvents()
to fetch pool initialization events - Filters events from the Uniswap V4 PoolManager contract
- Extracts pool keys (currency0, currency1, fee, tickSpacing, hooks) from event logs
- Adjust
START_BLOCK_NUMBER
andEND_BLOCK_NUMBER
for your needs - If you’d like to index these events in real-time, use
viem
swatchContractEvent
instead
2. Pool Data Loading (utils.ts
)
Contains utilities for enriching pool data with on-chain information.
- Uses Uniswap V4 StateView contract for efficient state queries
- Handles both ERC20 tokens and native ETH (zero address)
3. Token Classification Logic
currency0
or currency1
in the pool - so we attempt to fetch the platform referrer address for both. For tokens like WETH which don’t have that view function available, it will just fall back to the zero address. If either of the currencies return a valid platform referrer address that also matches the referrer address used by the Base App, we classify the coin as having come from the Base App.
4. Liquidity Calculations
liquidity
amount we loaded previously for a pool, we utilize Uniswap’s SDK to do some math and get human-friendly versions of how much of each token is available in the pool as total liquidity.
Alternative Implementation Approaches
Event Data Sources
This implementation uses direct JSON-RPC calls viaviem
, but you can adapt it for other data sources:
Subgraphs: If you’re already using The Graph Protocol, modify the event fetching logic to query a Uniswap V4 subgraph instead of making direct RPC calls. Replace the getContractEvents
call with GraphQL queries.
Indexing Services: For projects using third-party indexing services with their own APIs, substitute their event APIs while maintaining the same pool key extraction logic.
Real-time Monitoring: Convert from batch processing to real-time by setting up WebSocket subscriptions to new block events and processing pools as they’re created.
Data Storage
The current implementation prints metadata to console, but you might want to:- Store results in a database for persistent analysis
- Send data to external APIs or webhooks
- Cache results to avoid re-processing known pools
Output
The output metadata object contains the following fields:Pool Identifiers
id
: Unique pool identifier hashkey
: Complete pool key object with currencies, fee, tickSpacing, and hooks
Currency Information
currency0/currency1.name
: Human-readable token namecurrency0/currency1.symbol
: Token symbol (e.g., “USDC”, “WETH”)currency0/currency1.decimals
: Token decimal places for formattingcurrency0/currency1.address
: Contract address
Price Data
sqrtPriceX96
: Current pool price in Uniswap’s sqrt formattick
: Current tick (logarithmic price representation)currency0Price
: Price of currency0 in terms of currency1currency1Price
: Price of currency1 in terms of currency0currency0PriceHumanReadable
: Formatted price stringcurrency1PriceHumanReadable
: Formatted price string
Liquidity Metrics
liquidity
: Total pool liquidity in Uniswap’s internal formatliquidityCurrency0
: Amount of currency0 in the pool (raw)liquidityCurrency1
: Amount of currency1 in the pool (raw)liquidityCurrency0HumanReadable
: Formatted amount with symbolliquidityCurrency1HumanReadable
: Formatted amount with symbol
Classification
coinType
: Type of Zora token (“ZORA_CREATOR_COIN” or “ZORA_V4_COIN”)appType
: Application ecosystem (“ZORA” or “TBA”)
Use Cases for Metadata
Analytics & Monitoring
- Price Tracking: Monitor token prices and price movements over time
- Liquidity Analysis: Track total value locked (TVL) in various token pools
- Market Discovery: Identify new tokens entering the ecosystem
Trading & DeFi
- Arbitrage Detection: Compare prices across different pools or DEXs
- Liquidity Provider Analysis: Evaluate pool attractiveness for LP positions
- Volume Analysis: Track trading activity in specific token categories
Ecosystem Analysis
- Token Categorization: Understand which tokens belong to which ecosystems
- Adoption Metrics: Monitor growth of Zora and Base App token usage
- Cross-chain Comparison: Compare activity across different networks
Integration Projects
- Portfolio Tracking: Include Zora/Base App tokens in portfolio management apps
- Wallet Integration: Enhance wallet UIs with ecosystem-specific token information
- DeFi Protocols: Build lending, staking, or yield farming products around these tokens
Configuration
Environment Variables
RPC_URL
: Base chain RPC endpoint (required)
Block Range
ModifySTART_BLOCK_NUMBER
and END_BLOCK_NUMBER
in index.ts
to scan different ranges or implement continuous monitoring.
Hook Addresses
Add new hook addresses to the classification logic as new Zora contracts are deployed.Getting Started
Extensions & Modifications
This starter guide can be extended in many ways:- Add support for additional hook contracts as they’re deployed
- Include historical price and volume data
- Add alerts for significant liquidity changes
- Build web interfaces for browsing discovered pools
- Integrate with portfolio tracking or trading applications