1

I am working on a project where I need to monitor when a specific wallet buys or sells tokens. While I am familiar with using getAccountInfo to obtain information about what an account currently holds, I haven't found a way to specifically track transactions related to buying or selling tokens.

Could anyone suggest an API or a method that allows tracking these specific types of transactions? Any pointers on the relevant API methods or instructions would be greatly appreciated.

Thank you in advance!

1 Answer 1

1

u can use websockets and subscribe to an account

https://solana.com/docs/rpc/websocket/accountsubscribe

an example from solana cookbook

import asyncio
from solders.keypair import Keypair
from solana.rpc.websocket_api import connect

async def main():
    async with connect("wss://api.devnet.solana.com") as websocket:
        # Create a Test Wallet
        wallet = Keypair()
        # Subscribe to the Test wallet to listen for events
        await websocket.account_subscribe(wallet.pubkey())
        # Capture response from account subscription 
        first_resp = await websocket.recv()
        print("Subscription successful with id {}, listening for events \n".format(first_resp.result))
        updated_account_info = await websocket.recv()
        print(updated_account_info)
        
asyncio.run(main())

seems the resp is a dictionary in a list so i adapted the above code to work with this structure

import asyncio
from solders.keypair import Keypair
from solana.rpc.websocket_api import connect


async def main():
    async with connect("wss://api.devnet.solana.com") as websocket:
        # Create a Test Wallet
        wallet = Keypair()
        # Subscribe to the Test wallet to listen for events
        await websocket.account_subscribe(wallet.pubkey())
        # Capture response from account subscription
        first_resp = await websocket.recv()
        result_value = first_resp[0].result
        print(f"Subscription successful with id {result_value}, listening for events\n")
        updated_account_info = await websocket.recv()
        print(updated_account_info)


asyncio.run(main())

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.