參考 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}
這個(gè)代碼有好幾個(gè)需要改一下
w3 需要換成自己的infura的 wss,infura http的不支持ethFilter
需要把超時(shí)加進(jìn)去 https://web3py.readthedocs.io/en/stable/providers.html
-
createFilter(fromBlock=6627917, toBlock=6627927) 需要這樣慢慢請(qǐng)求 for循環(huán)吧 不然怎么都會(huì)超時(shí)唉
PROVIDER = "wss://mainnet.infura.io/ws/v3/api-key"
w3 = Web3(Web3.WebsocketProvider(PROVIDER, websocket_kwargs={'timeout': 60}))