> ## Documentation Index
> Fetch the complete documentation index at: https://www.helius.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# programSubscribe

> Đăng ký theo dõi một chương trình để nhận thông báo khi số lamport hoặc dữ liệu của một tài khoản thuộc sở hữu của chương trình đó thay đổi.

## Điểm cuối

WebSocket khả dụng trên mainnet và devnet tại các URL sau:

* **Mainnet** `wss://mainnet.helius-rpc.com/?api-key=<api-key>`
* **Devnet** `wss://devnet.helius-rpc.com/?api-key=<api-key>`

<Note>WebSocket có bộ hẹn giờ ngắt kết nối sau 10 phút không hoạt động; bạn rất nên triển khai kiểm tra tình trạng và gửi ping mỗi phút để duy trì kết nối WebSocket.</Note>

## Xác thực

<ParamField query="api-key" type="string" required>
  Khóa API Helius của bạn. Bạn có thể nhận khóa miễn phí trong [bảng điều khiển](https://dashboard.helius.dev/api-keys).
</ParamField>

## Nội dung yêu cầu

<ParamField body="params" type="array" required>
  <Expandable title="properties" defaultOpen>
    <ParamField body="programId" type="string" required>
      Khóa công khai của `program_id`, dưới dạng chuỗi được mã hóa base-58.
    </ParamField>

    <ParamField body="config" type="object">
      Đối tượng cấu hình chứa các trường sau:

      <ParamField body="commitment" type="string">
        Mức commitment cho đăng ký. Có thể là `finalized`, `confirmed` hoặc `processed`.
      </ParamField>

      <ParamField body="filters" type="array">
        Mảng các đối tượng bộ lọc cần áp dụng.
      </ParamField>

      <ParamField body="encoding" type="string">
        Định dạng mã hóa cho dữ liệu tài khoản. Có thể là `base58`, `base64`, `base64+zstd` hoặc `jsonParsed`.

        * `base58` có tốc độ chậm
        * Kiểu mã hóa `jsonParsed` cố gắng sử dụng các trình phân tích cú pháp trạng thái dành riêng cho chương trình để trả về dữ liệu trạng thái tài khoản rõ ràng và dễ đọc hơn
        * Nếu yêu cầu `jsonParsed` nhưng không tìm thấy trình phân tích cú pháp, trường này sẽ chuyển về mã hóa nhị phân; có thể nhận biết điều này khi trường dữ liệu có kiểu string.
      </ParamField>

      <ParamField body="notifyOn" type="string" deprecated>
        **Không còn dùng — không thực hiện thao tác nào kể từ Agave 4.2.** Việc đặt `notifyOn` không có tác dụng. Trường này sẽ bị xóa trong tương lai.
      </ParamField>
    </ParamField>
  </Expandable>
</ParamField>

## Phản hồi

<ResponseField name="result" type="integer">
  ID đăng ký (cần thiết để hủy đăng ký)
</ResponseField>

## Định dạng thông báo

Định dạng thông báo là một đối tượng tài khoản chương trình **duy nhất**, giống như trong phương thức RPC HTTP `getProgramAccounts`.

<RequestExample>
  ```json Request theme={"system"}
  {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "programSubscribe",
    "params": [
      "11111111111111111111111111111111",
      {
        "encoding": "base64",
        "filters": [{ "dataSize": 80 }]
      }
    ]
  }
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={"system"}
  {
    "jsonrpc": "2.0",
    "result": 24040,
    "id": 1
  }
  ```

  ```json Notification (base58) theme={"system"}
  {
    "jsonrpc": "2.0",
    "method": "programNotification",
    "params": {
      "result": {
        "context": {
          "slot": 5208469
        },
        "value": {
          "pubkey": "H4vnBqifaSACnKa7acsxstsY1iV1bvJNxsCY7enrd1hq",
          "account": {
            "data": [
              "11116bv5nS2h3y12kD1yUKeMZvGcKLSjQgX6BeV7u1FrjeJcKfsHPXHRDEHrBesJhZyqnnq9qJeUuF7WHxiuLuL5twc38w2TXNLxnDbjmuR",
              "base58"
            ],
            "executable": false,
            "lamports": 33594,
            "owner": "11111111111111111111111111111111",
            "rentEpoch": 636,
            "space": 80
          }
        }
      },
      "subscription": 24040
    }
  }
  ```

  ```json Notification (jsonParsed) theme={"system"}
  {
    "jsonrpc": "2.0",
    "method": "programNotification",
    "params": {
      "result": {
        "context": {
          "slot": 5208469
        },
        "value": {
          "pubkey": "H4vnBqifaSACnKa7acsxstsY1iV1bvJNxsCY7enrd1hq",
          "account": {
            "data": {
              "program": "nonce",
              "parsed": {
                "type": "initialized",
                "info": {
                  "authority": "Bbqg1M4YVVfbhEzwA9SpC9FhsaG83YMTYoR4a8oTDLX",
                  "blockhash": "LUaQTmM7WbMRiATdMMHaRGakPtCkc2GHtH57STKXs6k",
                  "feeCalculator": {
                    "lamportsPerSignature": 5000
                  }
                }
              }
            },
            "executable": false,
            "lamports": 33594,
            "owner": "11111111111111111111111111111111",
            "rentEpoch": 636,
            "space": 80
          }
        }
      },
      "subscription": 24040
    }
  }
  ```
</ResponseExample>
