0

a pleasure to be here, I am reviewing some network transactions but I do not fully understand how tracking works here, for example in the evm networks you could easily identify where transactions come from and thus be able to track them, in solana it seems complicated to me or Maybe I'm missing something, for example in this transaction https://solscan.io/tx/4MWLgd8BdyTSV2zSmRt5rK1MoyEH6Yy2XsHoqsw4tgKiBxNW2evVc86s1vdNdJYgXEarLVEommcthz5Wh1TZmvBp how can I track on the network every time a transaction is executed ? Do I use the sistem program wallet and filter by the instructions? Or how would I do it?

2
  • What do you mean by "track"? Add some details.
    – Serban
    Commented Nov 27, 2023 at 9:48
  • Greetings, exactly friend, is there a way?
    – Irzad
    Commented Nov 27, 2023 at 11:58

2 Answers 2

2

You probably want to use the websocket API to receive notifications of transactions as they arise. If you want to receive a notification anytime an account is included in a transaction, you can use the accountSubscribe endpoint, providing the pubkey for the account: https://docs.solana.com/api/websocket#accountsubscribe

This gives you the new state of the account whenever it's updated.

4
  • Greetings friend, thank you for your response, I hope you are having a good day....I understand, but which account do I subscribe to exactly to track a transaction like this?
    – Irzad
    Commented Nov 30, 2023 at 16:27
  • In that example, it seems like Cv9AMWo9V13ZjBGaeoE2qDBTjZxT6LddNsNY9rKNjQs8 is the account that you'll want to track. It's the fee-payer for the transaction and is funding a lot of other accounts being created
    – Jon C
    Commented Dec 1, 2023 at 12:36
  • Greetings friend, correct, my question is how I could "track" each tx that is made on that type of network, which account should I subscribe to to know each time someone creates a market
    – Irzad
    Commented Dec 1, 2023 at 15:31
  • Ah, there's the question finally! You can use programSubscribe with the program key, which is srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX. And then you'll need to know how the instructions are encoded. The repo is at github.com/openbook-dex/openbook-v2, so there should be enough information there!
    – Jon C
    Commented Dec 1, 2023 at 15:38
0

You can do this with LogSubscribe. Also to understand the solscan interface it's important you understand how accounts work in solana it is very different from Ethereum.

import asyncio
import websockets
import json
wallet_address = "Enter Target Wallet Address"
seen_signatures = set()

async def run():
   count = 0
   uri = "wss://api.mainnet-beta.solana.com"
   async with websockets.connect(uri) as websocket:
       # Send subscription request
       await websocket.send(json.dumps({
           "jsonrpc": "2.0",
           "id": 1,
           "method": "logsSubscribe",
           "params": [
               {"mentions": [wallet_address]},
               {"commitment": "finalized"}
           ]
       }))

       # Receive the first response
       first_resp = await websocket.recv()
       response_dict = json.loads(first_resp)
       if 'result' in response_dict:
          print("Subscription successful. Subscription ID: ", response_dict['result'])

       # Continuously read from the WebSocket
       async for response in websocket:
           response_dict = json.loads(response)           

           if 'params' in response_dict:

              print("New update received: ", response_dict['params'])
          
           else:
              print("Unexpected response: ", response_dict)
              

    asyncio.run(run())

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.