Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detecting pending TX's from a specific address? #2303

Closed
Raveboi334 opened this issue Jan 13, 2022 · 3 comments
Closed

Detecting pending TX's from a specific address? #2303

Raveboi334 opened this issue Jan 13, 2022 · 3 comments

Comments

@Raveboi334
Copy link

Raveboi334 commented Jan 13, 2022

Hi there, I was wondering if I was using the code wrong, but I am trying to figure out how to get pending transactions for a specific address.

I've tried: web3.eth.filter({'fromBlock': 'latest', 'toBlock': 'pending', 'address': 'MY ADDRESS'}) but it only shows mined (validated) transactions.

Is this a bug or is there any way to work around this?

Thank you.

@dbfreem
Copy link
Contributor

dbfreem commented Jan 18, 2022

So here is my understanding of filter based on what is in the docs. You can provide 'latest', 'pending' or a dictionary to web3.eth.filter(). You seem to be mixing the latest and pending functionality with the dictionary.

@dbfreem dbfreem mentioned this issue Jan 18, 2022
@fselmo
Copy link
Collaborator

fselmo commented Jan 19, 2022

@Raveboi334 @dbfreem The 'pending' keyword should technically work (using geth at least) but I don't believe you will get very good results unless you are running your own node. Many providers won't support pending in this way anyhow, as is the case with Infura. I'm going to close this as it isn't a bug but please let us know if you think there's a bug somewhere in here. Best of luck.

@fselmo fselmo closed this as completed Jan 19, 2022
@mrhouzlane
Copy link

@Raveboi334 , this works for me :

event_filter = web3.eth.filter({"address": CONTRACT_ADDRESS })

async def log_loop(event_filter, poll_interval):
    while True:
        for event in event_filter.get_new_entries():
            handle_event(event)
        await asyncio.sleep(poll_interval)

def main():
    options = Router
    # block_filter = w3.eth.filter('latest') #or 'pending'
    tx_filter = web3.eth.filter('pending')
    loop = asyncio.get_event_loop()
    try:
        loop.run_until_complete(
            asyncio.gather(
                # log_loop(block_filter, 2),
                log_loop(tx_filter, 2)))
    finally:
        loop.close() 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants