# Subscribing to Accounts

To receive account updates we use the <mark style="color:yellow;">accounts filter</mark> of the Subscribe request. The account filter has the following structure.

{% code overflow="wrap" %}

```json
{
  "slots": {},
  "accounts": {
      "accountLabel": {
        "account": string[], //account updates for these accounts 
        "owner": string[], //account updates for account with these owners
	"filters": {
	  "memcmp": {bytes and offset}  | undefined;
	  "datasize": string | undefined;
          "tokenAccountState": boolean | undefined;
        } 
  },
  "transactions": {},
  "blocks": {},
  "blocksMeta": {},
  "accountsDataSlice": [],
  "commitment": CommitmentLevel.CONFIRMED //commitment level, can be finalized or processed as well
}
```

{% endcode %}

Similar to the transactions filter, the first field under the accounts filter is the `accountLabel`, a <mark style="color:yellow;">user-defined label</mark> that helps you identify updates, especially when working with multiple filters. The `account` field specifies an array of <mark style="color:yellow;">account addresses</mark> for streaming account updates. The `owner` field streams updates for <mark style="color:yellow;">accounts owned</mark> by the specified addresses. Additionally, you can refine the data further by adding filters based on <mark style="color:yellow;">memcmp values</mark>, such as `bytes` and `dataSize`.

{% hint style="info" %}
The "key" at the start of all filters, (e.g. accountLabel, txnLabel) is a client-assigned label and can be set to any user-defined names.&#x20;
{% endhint %}

### Subscribe to account updates for a program

{% code overflow="wrap" %}

```json
{
  "slots": {},
  "accounts": {
    "pumpfun": {
      "owner": ["6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P"] //account updates will be streamed for accounts with this owner
    }
  },
  "transactions": {},
  "blocks": {},
  "blocksMeta": {},
  "accountsDataSlice": [],
  "commitment": CommitmentLevel.PROCESSED
}
```

{% endcode %}

To stream all account updates for a program, use the `account` field under the accounts filter. The `owner` field should specify the <mark style="color:yellow;">program's address</mark>, as all accounts belonging to the program are owned by the program address itself.

### Subscribe to account updates of an address

{% code overflow="wrap" %}

```json
{
  "slots": {
    "slots": {}
  },
  "accounts": {
    "sol/usdc": {
      "account": ["9AnFgHoXFysVcuFFX7QztDmzuH8r5ZFvyP4sYwn1XTj9"] // pool address when streaming pool updates
    }
  },
  "transactions": {},
  "blocks": {},
  "blocksMeta": {},
  "accountsDataSlice": [],
  "commitment": CommitmentLevel.CONFIRMED
};
```

{% endcode %}

The `account` array accepts the <mark style="color:yellow;">pool address</mark> for which updates are being streamed. This is especially useful when monitoring the state of specific accounts, such as those in liquidity pools, to track changes in real time.

### Subscribe to account updates using Memory compare (memcmp)

`memcmp` filters allow you to <mark style="color:yellow;">match</mark> specific portions of <mark style="color:yellow;">binary data</mark> within accounts, helping you include only those account updates that <mark style="color:yellow;">meet specific criteria</mark>. This makes them especially useful for targeting specific states or values in program-owned accounts. For instance, you can use a `memcmp` filter to track liquidity pool balances, monitor token ownership, or identify program-specific flags. A `memcmp` filter typically specifies three key parameters: `offset`, which defines the starting byte position in the account data to compare; `bytes`, the value to match at the specified offset; and Encoding (optional), which determines how the bytes are encoded, such as base64 or base58.

```json
{
  "slots": {},
  "accounts": {
    "raydium": {
      "account": [],
      "filters": [
        {
          "memcmp": {
            "offset": LIQUIDITY_STATE_LAYOUT_V4.offsetOf('marketProgramId').toString(), 
            "base58": "srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"
          }
        }
      ],
      "owner": ["675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"] 
    }
  },
  "transactions": {},
  "blocks": {},
  "blocksMeta": {
    "block": []
  },
  "accountsDataSlice": [],
  "commitment": CommitmentLevel.PROCESSED,
  "entry": {},
  "transactionsStatus": {}
}
```

For instance, this subscribe request streams updates for Raydium pool accounts with a `marketProgramId` equal to *<mark style="color:yellow;">serum</mark>*. The filter targets the `marketProgramId` field of the account, ensuring updates are streamed only for <mark style="color:yellow;">matching accounts</mark>.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.shyft.to/solana-yellowstone-grpc/docs/subscribing-to-accounts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
