Skip to content

Dex Explorer Script May 2026

while True: current_block = w3.eth.block_number

if current_block > last_block: print(f"\n--- New blocks: last_block+1 to current_block ---") for pair in monitored_pairs: # List of pair addresses swaps = get_recent_swaps(pair, last_block+1, current_block) for swap in swaps: if swap["amount0_out"] > 100: # Filter for large trades print(f"🐋 LARGE SWAP: swap['amount0_out'] tokens") last_block = current_block dex explorer script

swaps = [] for event in swap_filter.get_all_entries(): swaps.append( "block": event["blockNumber"], "sender": event["args"]["sender"], "amount0_in": event["args"]["amount0In"] / 1e18, "amount1_in": event["args"]["amount1In"] / 1e18, "amount0_out": event["args"]["amount0Out"] / 1e18, "amount1_out": event["args"]["amount1Out"] / 1e18, "to": event["args"]["to"] ) while True: current_block = w3

The data is out there – go explore it. Have you built your own DEX explorer? Found a clever way to detect sandwich attacks or new pool creations? Share your approach in the comments below. Share your approach in the comments below

A single swap transaction touches multiple smart contracts, emits several events, and alters the state of a liquidity pool. Manually tracing this on a block explorer like Etherscan is tedious.

if w3.is_connected(): print(f"Connected to chain: w3.eth.chain_id") A DEX like Uniswap V2 emits two critical events: Swap and Sync . We only need the ABI fragments for those events:

DEX_ABI = '''[ "anonymous": false, "inputs": [ "indexed": true, "name": "sender", "type": "address", "indexed": false, "name": "amount0In", "type": "uint256", "indexed": false, "name": "amount1In", "type": "uint256", "indexed": false, "name": "amount0Out", "type": "uint256", "indexed": false, "name": "amount1Out", "type": "uint256", "indexed": true, "name": "to", "type": "address" ], "name": "Swap", "type": "event" ]''' For a production script, you’d include the full factory and pair ABIs. But this is enough to get started. Here’s a function that fetches the last 100 blocks and extracts every swap event from a specific DEX router: