0

I have been using the same script written with web3.py for months now, which filters for events one block at a time. (Note that the contract is currently deployed on Polygon Mumbai Testnet) However, suddenly it seems that the event filters I have created are behaving strangely, and showing that any event is always included in two different blocks. You can see using the code below that the same event will be printed twice.

Does anyone have an insight on how to constantly scan for events while avoiding duplicates?

main.py:

from web3 import Web3
from web3.middleware import geth_poa_middleware
from web3._utils.filters import Filter

w3 = Web3(Web3.HTTPProvider('https://matic-mumbai.chainstacklabs.com'))

event_filter: Filter = w3.eth.filter({
 'address': ['0x5EE094C36B9ae110ddd10F10A770d288316369B6'],
 'topics': [['0xa09dd32955694000e96fcafeba044b4dbd4850f23f8ab83a94833731fc9e947f']],
 'fromBlock': 29683376,
 'toBlock': 29683377
})

events = event_filter.get_all_entries()

print(events)

event_filter: Filter = w3.eth.filter({
 'address': ['0x5EE094C36B9ae110ddd10F10A770d288316369B6'],
 'topics': [['0xa09dd32955694000e96fcafeba044b4dbd4850f23f8ab83a94833731fc9e947f']],
 'fromBlock': 29683377,
 'toBlock': 29683378
})

events = event_filter.get_all_entries()

print(events)
7
  • how do you know the event is included in two different blocks?
    – user253751
    Dec 14, 2022 at 16:45
  • @user253751 if you run the code above you will see the same event is included in both prints Dec 15, 2022 at 7:29
  • @user253751 if you change the block ranges to (29683375, 29683377) and (29683376, 29683378) respectively, the event is only printed twice. It is the most bizarre thing I've ever seen.... Dec 15, 2022 at 7:50
  • presumably the event is in block 29683377, so when you ask for blocks 29683376 and 29683377 you get the event, and when you ask for blocks 29683377 and 29683378 you also get the event. I don't see the problem?
    – user253751
    Dec 15, 2022 at 8:44
  • 1
    @user253751 But then how do you explain the result obtained from using these block ranges? (29683375, 29683377) and (29683376, 29683378) The event is only returned in the second range Dec 15, 2022 at 9:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.