createFilter event.Paircreated not working using moralis node

Hi, just starting out with blockchain development and I want to write a small program that listens for when a new pair is created. Currently I have this code:

node_url = 'node_url'
web3 = Web3(Web3.HTTPProvider(node_url))

uniswap_router = '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D'
uniswap_factory = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f'
uniswap_factory_abi = json.loads('ABI')

contract = web3.eth.contract(address=uniswap_factory, abi=uniswap_factory_abi)

def main():
    event_filter ='latest')

The problem is when I use infura this PairCreated function works fine but if I use moralis it gives me a filter not found error.

I would prefer to use moralis so is this a permission thing or do I have to use a different function that works with moralis?

you could try to do something similar as in this post: How to subscribe to OwnershipTransferred event for any smart contract [SOLVED]

What error are you getting?
Filter should work

exact error:
Traceback (most recent call last):
File “C:\Users\Do Yugen\PycharmProjects\octaraket2\”, line 67, in
File “C:\Users\Do Yugen\PycharmProjects\octaraket2\”, line 57, in main
File “C:\Python310\lib\asyncio\”, line 641, in run_until_complete
return future.result()
File “C:\Users\Do Yugen\PycharmProjects\octaraket2\”, line 36, in log_loop
for PairCreated in event_filter.get_new_entries():
File “C:\Users\Do Yugen\PycharmProjects\octaraket2\venv\lib\site-packages\web3_utils\”, line 160, in get_new_entries
log_entries = self._filter_valid_entries(self.eth_module.get_filter_changes(self.filter_id))
File “C:\Users\Do Yugen\PycharmProjects\octaraket2\venv\lib\site-packages\web3\”, line 57, in caller
result = w3.manager.request_blocking(method_str,
File “C:\Users\Do Yugen\PycharmProjects\octaraket2\venv\lib\site-packages\web3\”, line 187, in request_blocking
return self.formatted_response(response,
File “C:\Users\Do Yugen\PycharmProjects\octaraket2\venv\lib\site-packages\web3\”, line 168, in formatted_response
raise ValueError(response[“error”])
ValueError: {‘code’: -32000, ‘message’: ‘filter not found’}

cryptokid thank you! will see what I can extract from that. Using python but will switch if i need to

Hey CryptoKid. So i learnt node.js just so i can use the provided code.
What I have done is simply copy paste the actual code into .js file (main .js file).
And it works perfectly, only thing is that I suspect its only picking up on one or two events and then stops listening as I would get events when I launch the app but after a couple, I stop receiving the events.

Could this have something to do with the code not being in an html file?

what particular RPC node are you using? archive or non archive?
the chain is eth mainnet?

you could also sync events in your Moralis server db if you want:

I am using the Fantom main net speedy node (wss), not sure how to check if archive or non archive? The sync events solution seems really nice. Is there any way to access the data on the dashboard through js? Ie to listen for when the event happens via the dashboard?

or you could connect directly to mongo db if you want How to do database backups?

1 Like

I cant help but laugh at how much easy this live-queries method is… Thank you very much!!

hello, i got the same error i use bsc blockchain, any help from you?

Can you give more info? Maybe some code example