参考 https://www.reddit.com/r/UniSwap/comments/atddo2/effective_way_to_get_all_uniswap_exchange/
from web3.auto import w3
abi = [{"name": "NewExchange", "inputs": [{"type": "address", "name": "token", "indexed": True}, {"type": "address", "name": "exchange", "indexed": True}], "anonymous": False, "type": "event"}]
uniswap = w3.eth.contract('0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95', abi=abi)
events = uniswap.events.NewExchange.createFilter(fromBlock=6627917).get_all_entries()
token_exchange = {e.args.token: e.args.exchange for e in events}
这个代码有好几个需要改一下
w3 需要换成自己的infura的 wss,infura http的不支持ethFilter
需要把超时加进去 https://web3py.readthedocs.io/en/stable/providers.html
-
createFilter(fromBlock=6627917, toBlock=6627927) 需要这样慢慢请求 for循环吧 不然怎么都会超时唉
PROVIDER = "wss://mainnet.infura.io/ws/v3/api-key"
w3 = Web3(Web3.WebsocketProvider(PROVIDER, websocket_kwargs={'timeout': 60}))