0

I almost tried but getting failed. I am trying to fetch pending transaction. here is my code if anyone suggest that would be great.

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": "logsUnsubscribe",
           "params": [0]
       }))

    isResp = await websocket.recv()
    responseData = json.loads(isResp)

1 Answer 1

0

Be sure to follow the example at https://solana.com/docs/rpc/websocket/logssubscribe and the python example at https://github.com/michaelhly/solana-py/blob/cd811558cdf7b0ed7cdf31bf522870dafd03ee8d/tests/integration/test_websockets.py#L81, so you can do:

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": [ <ACCOUNT_THAT_YOU_CARE_ABOUT> ]
               },
               {
                   "commitment": "confirmed"
               }
            ]
       }))

    isResp = await websocket.recv()
    responseData = json.loads(isResp)

    # and later unsubscribe
    await websocket.send(json.dumps({
           "jsonrpc": "2.0",
           "id": 1,
           "method": "logsUnsubscribe",
           "params": [responseData["result"]] # pass in the subscription id
       }))

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.