6

I am using the python implementation of the web3 library.(https://github.com/pipermerriam/web3.py) Calling and interacting with contracts works fine, but when it comes to the event listener functionality, none of the fired events are registered by the program.

def transfer_callback(log_entry): print "Event fired"

filter = contract.on("DisplayChange", {})

filter.watch(transfer_callback)

Watching the contracts event in the Ethereum Wallet also works without problems, so the issue is definitely connected to python. Thank you in advance for any response.

2 Answers 2

1

you might want to look at the docs here, the example is quite clear:

def new_transaction_callback(transaction_hash):
    sys.stdout.write("New Block: {0}".format(transaction_hash))

new_transaction_filter = web3.eth.filter('pending')
new_transaction_filter.watch(new_transaction_filter)
# each time the client receieves a unmined transaction the
# `new_transaction_filter` function will be called with the transaction
# hash.

another good place to look at examples on how it should be implemented is in the tests folder, specifically here

1
  • 1
    the watch method is not present anymore i think 'LogFilter' object has no attribute 'watch' web3.py 5.19 Commented May 15, 2021 at 14:30
0

If you want to get contract event logs

def transfer_callback(log_entry): 
    print "Event fired"

contract = web3.eth.contract(abi, address)
contract.on("DisplayChange", {}, transfer_callback)

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.