Dex Explorer Script !full! [RECOMMENDED]
def get_recent_swaps(pair_address, from_block, to_block): contract = w3.eth.contract(address=pair_address, abi=DEX_ABI) # Create event filter swap_filter = contract.events.Swap.create_filter( from_block=from_block, to_block=to_block )
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:
pip install web3 requests python-dotenv Now, connect to Ethereum mainnet (or BSC, Polygon, etc.):
Enter the .
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.
def get_recent_swaps(pair_address, from_block, to_block): contract = w3.eth.contract(address=pair_address, abi=DEX_ABI) # Create event filter swap_filter = contract.events.Swap.create_filter( from_block=from_block, to_block=to_block )
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:
pip install web3 requests python-dotenv Now, connect to Ethereum mainnet (or BSC, Polygon, etc.):
Enter the .
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.