> ## Documentation Index
> Fetch the complete documentation index at: https://chainstack-docs-polygon-erigon-trace-deprecation.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# programSubscribe | Solana

> Subscribe to real-time changes for all accounts owned by a Solana program using programSubscribe. Get WebSocket updates on program account modifications.

## Parameters

* `publicKey` - The program ID (public key) to monitor, as a base-58 encoded string

* `<config>` - (optional) Configuration object:

  * `encoding` - Data encoding for the account data:

    * `"base58"` - Base-58 encoding (default)
    * `"base64"` - Base-64 encoding
    * `"base64+zstd"` - Compressed Base-64 encoding
    * `"jsonParsed"` - JSON format (if program supports it)

  * `filters` - (optional) Array of filter objects:

    * `memcmp` - Filter for memory comparison:

      * `offset` - Number of bytes into program account to start comparison
      * `bytes` - Data to match, as base-58 encoded string

    * `dataSize` - Filter for program account data size

  * `commitment` - (optional) The level of commitment desired when querying state. Default is "finalized".

## Response

* `result` - An integer subscription id (needed to unsubscribe)

* `subscription` - An object containing account information:

  * `pubkey` - The public key of the account that changed

  * `account` - Account information:

    * `lamports` - Number of lamports assigned to the account
    * `owner` - Base-58 encoded public key of the program this account is assigned to
    * `data` - Account data, encoded according to specified encoding parameter
    * `executable` - Boolean indicating if the account contains a program
    * `rentEpoch` - The epoch at which this account will next owe rent

## `programSubscribe` code examples

This example subscribes to all accounts owned by the pump.fun program.

<Info>
  Note that subscriptions require a WebSocket connection and [WebSocket cat](https://www.npmjs.com/package/wscat) for you to use this method in the console.

  Install WebSocket cat with:

  `npm install -g wscat`
</Info>

<CodeGroup>
  ```shell wscat theme={null}
  $ wscat -c YOUR_CHAINSTACK_WEBSOCKET_ENDPOINT
  # Wait for the connection to be established

  Connected (press CTRL+C to quit)

  > {"jsonrpc":"2.0","id":1,"method":"programSubscribe","params":["6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P",{"encoding":"jsonParsed","commitment":"finalized"}]}
  ```
</CodeGroup>

## Use case

The `programSubscribe` method is particularly useful for applications that need to monitor all accounts associated with a specific program. Common use cases include:

* DEX monitoring: Track changes to orderbooks, market states, and other trading-related accounts
* Token tracking: Monitor token program accounts for transfers and balance changes
* Gaming: Track game state changes across all player accounts
* DeFi applications: Monitor lending pools, staking positions, and other DeFi-related accounts
* Analytics platforms: Gather real-time data about program usage and account state changes

By subscribing to program account changes, applications can provide real-time updates and analytics without constantly polling the blockchain for changes to individual accounts.
