1

I have the following code that polls for transactions every second. I want to make it more responsive, and not use polling, but instead something quicker.

tx_all_pending = w3.eth.filter('pending')
while True:
    pending_txs = tx_all_pending.get_new_entries()
    ...
    time.sleep(1)

In javascript, this is done using web3.eth.subscribe with a callback function. Is there something similar in Python? I realize I could change the polling rate to something like 1 millisecond, but that would be a drag on the CPU.

I've tried:

def new_tx(tx):
    ...

tx_all_pending = w3.eth.filter('pending')
tx_all_pending.watch(new_tx) # 'TransactionFilter' object has no attribute 'watch'

I've also tried:

async def main():
    block = await w3.eth.coro_getBlock(100) # 'Eth' object has no attribute 'coro_getBlock'

asyncio_loop = asyncio.get_event_loop()
asyncio_loop.run_until_complete(main())

Thanks for any help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.