Start simple. Monitor one pair. Then expand to one DEX. Then to every DEX on three chains.
for event in swap_events: args = event["args"] print(f"From: args['sender'] | Amount0In: args['amount0In'] | Amount1Out: args['amount1Out']") A DEX explorer script transforms you from a passive blockchain observer into an active participant. Whether you’re building a trading bot, a dashboard, or just satisfying your curiosity, the ability to extract and decode on-chain DEX data is a superpower.
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 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"] )
Add a simple loop with a sleep interval to monitor swaps every 12 seconds (Ethereum block time): Start simple
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 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. Then to every DEX on three chains
while True: current_block = w3.eth.block_number