A blockchain indexer for Uniswap V4 swap events on Arbitrum using rindexer.
This project indexes Uniswap V4 Swap
events from the PoolManager contract on Arbitrum mainnet and stores them in a PostgreSQL database.
Contract Details:
- Network: Arbitrum (Chain ID: 42161)
- Contract: PoolManager (
0x360E68faCcca8cA495c1B759Fd9EEe466db9FB32
) - Events: Swap events with rapid polling (~50ms)
- Docker and Docker Compose
- rindexer CLI installed locally,
- Redis installed locally,
- Arbitrum RPC endpoint (e.g., Alchemy, Infura)
-
Clone the repository and navigate to the project directory
-
Set up environment variables:
cp .env.example .env
-
Edit
.env
file and add your RPC endpoint:DATABASE_URL=postgresql://postgres:postgres@localhost:5432/rindexer_uniswapv4indexer ARB_MAINNET_RPC=https://arb-mainnet.g.alchemy.com/v2/your-api-key-here REDIS_CONNECTION_URI=redis://localhost:6379
Start the PostgreSQL database in Docker:
docker compose up -d
This will:
- Create a PostgreSQL 16 container
- Set up the
rindexer_uniswapv4indexer
database - Expose the database on
localhost:5432
redis-server
Depending on the port, update REDIS_CONNECTION_URI accordingly. Default port: redis://localhost:6379
Run rindexer locally (connects to the containerized database):
rindexer start indexer
The indexer will:
- Connect to the PostgreSQL database running in Docker
- Start indexing Uniswap V4 swap events from Arbitrum
- Create necessary tables automatically
- Begin rapid polling for new events
docker ps
docker logs uniswap_indexer_postgres
PGPASSWORD=postgres psql -h localhost -p 5432 -U postgres -d rindexer_uniswapv4indexer
# Stop indexer
# Press Ctrl+C in the terminal running rindexer
# Stop PostgreSQL
docker compose down
.
├── README.md
├── docker-compose.yml # PostgreSQL container configuration
├── rindexer.yaml # Indexer configuration
├── abis/
│ └── PoolManager.abi.json # Uniswap V4 PoolManager ABI
├── .env # Environment variables
└── .env.example # Environment template
- Network: Arbitrum mainnet with rapid block polling
- Contract: Uniswap V4 PoolManager
- Events: Swap events only
- Storage: PostgreSQL backend
DATABASE_URL
: PostgreSQL connection stringARB_MAINNET_RPC
: Arbitrum RPC endpoint
- Ensure PostgreSQL container is running:
docker ps
- Check container health:
docker logs uniswap_indexer_postgres
- Verify connection:
PGPASSWORD=postgres psql -h localhost -p 5432 -U postgres -d rindexer_uniswapv4indexer
If you need to start fresh:
docker compose down
docker volume rm uniswapv4indexer_postgres_data
docker compose up -d
If port 5432 is already in use:
- Stop other PostgreSQL services
- Or modify the port in
docker-compose.yml
and updateDATABASE_URL
accordingly
The indexer uses a no-code approach with rindexer. To modify:
- Add new events: Edit
include_events
inrindexer.yaml
- Change networks: Update
networks
section inrindexer.yaml
- Modify contracts: Update contract details in
rindexer.yaml
After configuration changes, restart the indexer:
rindexer start indexer