See afterSwap in action
This is a live demo of a Uniswap V4 hook tracking swap statistics onchain. Swap below and watch the stats update in real-time!
Live Pool Statistics
Trigger the hook with a swap
Swap directly through the V4 pool to trigger the afterSwap hook. Use small amounts — limited liquidity.
Connect your wallet to swap
The afterSwap hook lifecycle
User Swaps
A user swaps WETH for MOLT (or vice versa) on the Uniswap V4 pool that has our hook attached.
Hook Triggers
After the swap executes, the PoolManager calls our afterSwap function with the swap details.
Stats Updated
We record the swap count, volumes, and timestamp. An event is emitted for off-chain indexing.
Understanding V4 Hooks
Hook Permissions
Hooks declare which lifecycle events they want to intercept. SwapStats only uses afterSwap — the minimal permission needed for read-only analytics.
Return Delta
Hooks can modify swap amounts by returning a non-zero delta. SwapStats returns 0 — it observes swaps without modifying them.
Onchain Storage
Stats are stored directly in the hook contract. No external indexer needed — query the blockchain directly for real-time data.
Event Emission
Events enable off-chain tracking and live updates. This UI listens for SwapRecorded events to show real-time swap activity.