Dex Explorer Script Best -
return swaps latest = w3.eth.block_number swaps = get_recent_swaps("0x...PAIR_ADDRESS...", latest-100, latest)
contract = w3.eth.contract(address=UNISWAP_V2_PAIR, abi=DEX_ABI) swap_events = contract.events.Swap.get_logs(from_block=18500000, to_block=18500100)
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
Start simple. Monitor one pair. Then expand to one DEX. Then to every DEX on three chains.
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"] ) return swaps latest = w3
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 w3 = Web3(Web3.HTTPProvider("YOUR_RPC_URL")) UNISWAP_V2_PAIR = "0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc" # USDC/WETH Then expand to one DEX
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.