Script - Dex Explorer

If you’ve ever wanted to peek under the hood of a decentralized exchange (DEX) like Uniswap or PancakeSwap, you’ve probably realized that while the data is public , it’s not exactly easy to read.

from web3 import Web3 import os from dotenv import load_dotenv load_dotenv() dex explorer script

from web3 import Web3 w3 = Web3(Web3.HTTPProvider("YOUR_RPC_URL")) UNISWAP_V2_PAIR = "0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc" # USDC/WETH If you’ve ever wanted to peek under the

contract = w3.eth.contract(address=UNISWAP_V2_PAIR, abi=DEX_ABI) swap_events = contract.events.Swap.get_logs(from_block=18500000, to_block=18500100) Step 4: Making It Useful – Real-Time Monitoring

for s in swaps[:5]: print(f"Swap by s['sender']: s['amount0_out'] tokens out") Hardcoding a single pair address is fine for testing. A real explorer would query a factory contract to discover all pairs dynamically. Step 4: Making It Useful – Real-Time Monitoring A script that runs once is a toy. A script that runs forever is a tool.