Solana listen for new transactions on certain wallet (with Solana.py)

1k views Asked by At

I need to listen for new transactions(solana transfers) on a certain wallet, from python code from these transactions I need to take the sender's wallet and how many solans were transferred

also i need to fetch transactions(solana transfers) from certain wallet

all this i need for implement payment by solana(in my react+django web-app) maybe my approach not the most right one

in docs i found accountSubscribe, logsSubscribe and signatureSubscribe , but i don't understand what is signatures, logs and can i get new transfers from account that i subscribed

async with connect("wss://api.devnet.solana.com") as websocket:
    # this code works with devnet, how can i subscribe on mainnet?
    await websocket.logs_subscribe()
    first_resp = await websocket.recv()
    print(f'{first_resp = }')
    subscription_id = first_resp.result
    print(f'{subscription_id = }')
    next_resp = await websocket.recv()
    print(next_resp)
1

There are 1 answers

2
noah On

A possible solution would be to look at the most recent Block with a combination of getBlockHeight and getBlock and check for all the transactions in there.

To improve this, the script could only iterate over the block when detecting a change in getBalance on the Public Key of your wallet.


I'm working on a minimal example and providing it to this answer as soon as possible.