3

I am developing a software that listens for pending transactions.

...
web3 = Web3(HTTPProvider(cfg.eth_node_url))
web3_pending_filter = web3.eth.filter('pending')
transaction_list = web3.eth.getFilterChanges(web3_filter.filter_id)
...

In documentation of web3.py here is written that filter's getFilterChanges method should return transaction objects (list of dictionaries), but I am receiving list of hashes only. How can I get list of 'full' transactions from filter?

2 Answers 2

3

The docs you linked to are showing examples from filtering for events. Since you are filtering for pending transactions, it will be a bit different.

When listing pending transactions, you only get the transaction hashes, as specified in the json-rpc spec:

For filters created with eth_newPendingTransactionFilter the return are transaction hashes (DATA, 32 Bytes), e.g. ["0x6345343454645..."].

So you would get the list of transaction details using something like:

transaction_hashes = web3.eth.getFilterChanges(web3_filter.filter_id)
transactions = [web3.eth.getTransaction(h) for h in transaction_hashes]
0

You can get transaction details via

web3.eth.getTransaction(txnHash) 

If no transaction for the given hash can be found, then this function will instead return None. https://web3py.readthedocs.io/en/stable/examples.html#looking-up-transactions

In the following paragraph in the above documentation, you can check if the transaction has been mined(included into the blockchain) or not:

web3.eth.getTransactionReceipt(txnHash)

If the transaction has not yet been mined then this method will return None.

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.