OpenInfra.sh is now live - Solana infrastructure, included with every server. LEARN MORE HERE >

OpenInfra.shopeninfra.sh

programSubscribe

Receive a notification for every account owned by a program whenever any of those accounts change.

Basic subscription

ws.send(JSON.stringify({  jsonrpc: "2.0",  id: 1,  method: "programSubscribe",  params: [    "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",    {      encoding: "jsonParsed",      commitment: "confirmed",      filters: [        { dataSize: 165 },   // SPL token account data size      ],    },  ],})); // Notification shape:// { "method": "programNotification",//   "params": {//     "result": {//       "context": { "slot": 312449201 },//       "value": {//         "pubkey": "aBc123...",//         "account": { "lamports": 2039280, "data": {...}, "owner": "...", ... }//       }//     },//     "subscription": 42//   }// }

Filtering with memcmp

Apply memcmp to match only accounts whose raw data has specific bytes at a given offset:

// Filter: only USDC token accountsws.send(JSON.stringify({  jsonrpc: "2.0",  id: 1,  method: "programSubscribe",  params: [    "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",    {      encoding: "jsonParsed",      commitment: "confirmed",      filters: [        { dataSize: 165 },        {          memcmp: {            offset: 0,            bytes: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",          }        },      ],    },  ],}));