0

I am trying to filter Transfer events from my local ethereum node using web3 py. I have created a venv in visual studio code. My code is as follows:

def decodeLogswithfilter(t1, t2, abi1, addr):
    mycontract = geth.eth.contract(address=addr, abi=abi1)
    filter = mycontract.eventFilter(
        'Transfer', {'fromBlock': t1, 'toBlock': t2})
    eventlist = filter.get_all_entries
    print(eventlist)

decodeLogswithfilter(start, ending_block,
                         abi['result'], geth.toChecksumAddress(current_addr))

I have also tried using createFilter as well but it gives me the same error that Contract object has no attribute eventFilter.

Traceback (most recent call last):
  File "/mnt/ssd/erc721/queryBlockchain.py", line 150, in <module>
    abi['result'], geth.toChecksumAddress(current_addr))
  File "/mnt/ssd/erc721/queryBlockchain.py", line 71, in decodeLogswithfilter
    filter = mycontract.eventFilter(
AttributeError: 'Contract' object has no attribute 'eventFilter'

I have also tried upgrading my web3 package as suggested online, but the error didn't resolve.

1 Answer 1

1

Replace

filter = mycontract.eventFilter(
        'Transfer', {'fromBlock': t1, 'toBlock': t2})
eventlist = filter.get_all_entries

with

filter = mycontract.events.Transfer.createFilter(fromBlock=t1, toBlock=t2 )
filter.get_all_entries()         

assuming Transfer is the eventname in solidity, This is for web3==5.5.1 version.

7
  • I did and got the following error Traceback (most recent call last): File "/home/ethereumpc1/.local/lib/python3.6/site-packages/web3/providers/ipc.py", line 239, in make_request raw_response += sock.recv(4096) socket.timeout: timed out
    – mzaidi
    Apr 10, 2020 at 18:12
  • Make sure your local eth blockchain is working, This error implies that connection couldn't be established. Apr 10, 2020 at 18:15
  • The local blockchain is working, but the code is still throwing the same error.
    – mzaidi
    Apr 11, 2020 at 15:25
  • It seems everytime i run the code the node gets disconnected and the system hangs. Im using the system remotely through teamviewer. Is it because of a poor internet connection?
    – mzaidi
    Apr 11, 2020 at 15:46
  • Are u talking about remix? Apr 11, 2020 at 18:01

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.