> ## 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.

# accountSubscribe

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

## Điểm cuối

WebSocket khả dụng trên mainnet và devnet qua 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 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

<ParamField body="params" type="array" required>
  <Expandable title="properties" defaultOpen>
    <ParamField body="pubkey" type="string" required>
      Khóa công khai của tài khoản, dưới dạng chuỗi được mã hóa base-58.
    </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 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 phù hợp, trường này sẽ chuyển về mã hóa nhị phân; có thể nhận biết khi trường dữ liệu có kiểu chuỗi.
    </ParamField>

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

    <ParamField body="notifyOn" type="string" deprecated>
      **Đã ngừng sử 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 vào một thời điểm sau.
    </ParamField>
  </Expandable>
</ParamField>

## Phản hồi

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

<RequestExample>
  ```json Request theme={"system"}
  {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "accountSubscribe",
    "params": [
      "CM78CPUeXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNH12",
      {
        "encoding": "jsonParsed",
        "commitment": "finalized"
      }
    ]
  }
  ```
</RequestExample>

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

  ```json Message (base58) theme={"system"}
  {
    "jsonrpc": "2.0",
    "method": "accountNotification",
    "params": {
      "result": {
        "context": {
          "slot": 5199307
        },
        "value": {
          "data": [
            "11116bv5nS2h3y12kD1yUKeMZvGcKLSjQgX6BeV7u1FrjeJcKfsHPXHRDEHrBesJhZyqnnq9qJeUuF7WHxiuLuL5twc38w2TXNLxnDbjmuR",
            "base58"
          ],
          "executable": false,
          "lamports": 33594,
          "owner": "11111111111111111111111111111111",
          "rentEpoch": 635,
          "space": 80
        }
      },
      "subscription": 23784
    }
  }
  ```

  ```json Message (jsonParsed) theme={"system"}
  {
    "jsonrpc": "2.0",
    "method": "accountNotification",
    "params": {
      "result": {
        "context": {
          "slot": 5199307
        },
        "value": {
          "data": {
            "program": "nonce",
            "parsed": {
              "type": "initialized",
              "info": {
                "authority": "Bbqg1M4YVVfbhEzwA9SpC9FhsaG83YMTYoR4a8oTDLX",
                "blockhash": "LUaQTmM7WbMRiATdMMHaRGakPtCkc2GHtH57STKXs6k",
                "feeCalculator": {
                  "lamportsPerSignature": 5000
                }
              }
            }
          },
          "executable": false,
          "lamports": 33594,
          "owner": "11111111111111111111111111111111",
          "rentEpoch": 635,
          "space": 80
        }
      },
      "subscription": 23784
    }
  }
  ```
</ResponseExample>
