optimism
optimism copied to clipboard
Dealing with filter using QuickNode web-socket and web3.py raises ValueError: {'code': -32000, 'message': 'filter not found'}
I was trying to listen the events emitted by contracts by the use of web3.py and QuickNode websocket, but got "ValueError: {'code': -32000, 'message': 'filter not found'}" as a result. The same code is working well when I tried connect other chains but only failing with optimism.
Thanks in advance and do let me know if any further information needed.
I set up the filter in this way:
event_filter = self.factoryContract.events.PairCreated.createFilter(fromBlock="latest")
OPTIMISM_ENDPOINT = "wss://floral-autumn-wind.optimism.quiknode.pro/( api key here )/"
Relevant code: (template: https://web3py.readthedocs.io/en/stable/filters.html)
def log_loop(self, event_filter, poll_interval):
while True:
try:
for event in event_filter.get_new_entries():
self.handle_event(event)
except Exception as e:
print(e)
print(self.network, self.name, "filter failed")
event_filterr = self.factoryContract.events.PairCreated.createFilter(
fromBlock="latest")
time.sleep(poll_interval)
def execute(self):
event_filter = self.factoryContract.events.PairCreated.createFilter(
fromBlock="latest")
# event_filter = self.w3.eth.filter({"address":self.factoryContract.address})
worker = Thread(target=self.log_loop, args=(event_filter, 5), daemon=True)
worker.start()
while True:
self.running
Full error log:
Exception in thread Thread-3:
Traceback (most recent call last):
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/Users/user/OneDrive - HKUST Connect/GitHub/factory-alert-bot/Connector.py", line 116, in execute
print(event_filter.get_all_entries())
File "/Users/user/.local/share/virtualenvs/factory-alert-bot-JllLHjlQ/lib/python3.8/site-packages/web3/_utils/filters.py", line 164, in get_all_entries
log_entries = self._filter_valid_entries(self.eth_module.get_filter_logs(self.filter_id))
File "/Users/user/.local/share/virtualenvs/factory-alert-bot-JllLHjlQ/lib/python3.8/site-packages/web3/module.py", line 57, in caller
result = w3.manager.request_blocking(method_str,
File "/Users/user/.local/share/virtualenvs/factory-alert-bot-JllLHjlQ/lib/python3.8/site-packages/web3/manager.py", line 198, in request_blocking
return self.formatted_response(response,
File "/Users/user/.local/share/virtualenvs/factory-alert-bot-JllLHjlQ/lib/python3.8/site-packages/web3/manager.py", line 171, in formatted_response
raise ValueError(response["error"])
ValueError: {'code': -32000, 'message': 'filter not found'}
Environment
Package Version
------------------ ---------
aiohttp 3.8.1
aiosignal 1.2.0
async-timeout 4.0.2
attrs 21.4.0
base58 2.1.1
bitarray 1.2.2
certifi 2021.10.8
charset-normalizer 2.0.10
cytoolz 0.11.2
eth-abi 2.1.1
eth-account 0.5.6
eth-hash 0.3.2
eth-keyfile 0.5.1
eth-keys 0.3.4
eth-rlp 0.2.1
eth-typing 2.3.0
eth-utils 1.10.0
frozenlist 1.3.0
hexbytes 0.2.2
idna 3.3
ipfshttpclient 0.8.0a2
jsonschema 3.2.0
lru-dict 1.1.7
multiaddr 0.0.9
multidict 6.0.1
netaddr 0.8.0
parsimonious 0.8.1
pip 21.3.1
protobuf 3.19.3
pycryptodome 3.12.0
pyrsistent 0.18.1
requests 2.27.1
rlp 2.0.1
setuptools 60.5.0
six 1.16.0
toolz 0.11.2
urllib3 1.26.8
varint 1.0.2
web3 5.26.0
websockets 9.1
wheel 0.37.1
yarl 1.7.2