5

If I understand correctly, in web3.js the allevents method enables a contract event to be monitored.

is there an equivalent in python ?

1
  • 1
    Do you mean is there a Python based API similar to web3.js that can listen for events?
    – dbryson
    Apr 19, 2016 at 23:46

3 Answers 3

2

If you want to do local testing of your contract, you can use PyEthereum's tester to capture and view events from your contract via the ABIContract class.

If you're looking for a Python based RPC client you may want to look at ethjsonrpc. It appears ethjsonrpc has support for event functions.

2

response to self but might be handy for others, there is a library called web3.py https://github.com/pipermerriam/web3.py that let you create filters (http://web3py.readthedocs.io/en/latest/filters.html)

you do it by creating a filter object, then you add a watch method to it that returns a callback function

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)
2
  • new_transaction_filter does not have a method called watch() @euri10
    – alper
    Jun 25, 2018 at 10:47
  • If you are using Infura than this won't work. You have to set up your own node Dec 17, 2019 at 6:01
0

2023

  • Using Ape you can fetch all of the event logs related to any event like this
  • THis is an example of getting the PairCreated event of the uniswap v2 router.
from ape import project

address = "0xdead"

#contract = project.ContractName.at(address)
contract = project.IUniswapV2Factory.at(address)

for logs in contract.PairCreated:
    print(logs)
1

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.