4

is there any way to get pending transaction for a specified address? I can filter them on bscscan here, but I can't do the same in my web3py code. I can get all pending transaction for current pending block but I can't filter them. I can do:

txHashPending = w3.eth.filter('latest').get_all_entries()

and I get transactionHashes for pending transactions. I tried doing:

txHashPending = w3.eth.filter({'fromBlock':'pending','toBlock':'pending','from':'0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56'}).get_all_entries()

but it returned already validated/mined transactions.

3 Answers 3

1

Super late to this but since there's no answer I'll respond in case it helps you or someone else. You can now achieve this using the WebsocketProviderV2 (in web3.py v7 this name might change) via a websocket connection.

import asyncio
from web3 import (
    AsyncWeb3,
    WebsocketProviderV2,
)

async def get_pending_txs():
    async with AsyncWeb3.persistent_websocket(WebsocketProviderV2("wss://...")) as w3:
        # `True` here is for "full transactions" rather than just the hashes (default)
        sub_id = await w3.eth.subscribe("newPendingTransactions", True)
        print(f"sub_id: {sub_id}\n")

        async for message in w3.ws.process_subscriptions():
            # subscriptions will have "subscription" (the sub_id) and "result" keys
            if message.get("result", {}).get("from") == "0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56":
                print(f"tx: {message.get('result')}")  # result is the full transaction

asyncio.run(get_pending_txs())

Keep in mind the provider is in beta and some changes to method names might take place. This example is using web3.py v6.15.0.

0

You could try to get the pending transactions with the 'pending' filter and then iterate over the pending entries. Then you can get the transaction receipt, which contains the 'from' and 'to' attributes.

filter = w3.eth.filter('pending')
new_entries = filter.get_new_entries()

for entry in new_entries:             
    tx = w3.eth.getTransaction(entry)
    if(tx.from == "yourAddress"):
        print("got pending transaction from: ", tx.from)
0

You could request full mempool streaming then just display transactions to a specific address: (ethers.js)

if (transactionInfo.to == 0xE592427A0AEce92De3Edee1F18E0157C05861564){ console.log('Found'); } else if (transactionInfo.to == null) { console.log("init tx"); }

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.