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

# Đăng ký

> Đăng ký nhận thông tin cập nhật về tài khoản, giao dịch, khối và slot để nhận thông báo theo thời gian thực bằng API gRPC hiệu năng cao.

<hide>
  ## Điểm cuối

  Các dịch vụ gRPC có sẵn trên mainnet và devnet với các URL sau:

  * **Mainnet** `https://laserstream-mainnet.helius-rpc.com:443`
  * **Devnet** `https://laserstream-devnet.helius-rpc.com:443`
</hide>

## Xác thực

<ParamField query="x-token" 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>

## Thông điệp

API gRPC hỗ trợ nhiều loại đăng ký có thể kết hợp trong một yêu cầu duy nhất:

<ParamField body="accounts" type="object">
  Đăng ký nhận thông tin cập nhật về tài khoản. Trả về dữ liệu khi các tài khoản được chỉ định
  bị sửa đổi.

  <Expandable title="properties" defaultOpen>
    <ParamField body="account" type="array">
      Mảng khóa công khai của các tài khoản cần giám sát.
    </ParamField>

    <ParamField body="owner" type="array">
      Mảng khóa công khai của chủ sở hữu cần giám sát (tất cả tài khoản do các chương trình này sở hữu).
    </ParamField>

    <ParamField body="filters" type="object">
      Các bộ lọc tùy chọn cần áp dụng.

      <Expandable title="filter options">
        <ParamField body="memcmp" type="object">
          Lọc theo các byte cụ thể tại một độ lệch trong dữ liệu tài khoản.

          <Expandable title="properties">
            <ParamField body="offset" type="integer">
              Vị trí tính theo byte để bắt đầu so sánh dữ liệu.
            </ParamField>

            <ParamField body="bytes" type="string">
              Dữ liệu dùng để so sánh (định dạng byte).
            </ParamField>

            <ParamField body="base58" type="string">
              Dữ liệu dùng để so sánh (định dạng base58).
            </ParamField>

            <ParamField body="base64" type="string">
              Dữ liệu dùng để so sánh (định dạng base64).
            </ParamField>
          </Expandable>
        </ParamField>

        <ParamField body="datasize" type="integer">
          Lọc theo kích thước chính xác của dữ liệu tài khoản tính bằng byte.
        </ParamField>

        <ParamField body="token_account_state" type="boolean">
          Chỉ lọc các tài khoản token.
        </ParamField>

        <ParamField body="lamports" type="object">
          Lọc theo số dư SOL bằng các phép so sánh.

          <Expandable title="comparison operators">
            <ParamField body="eq" type="integer">
              Bằng số lượng được chỉ định.
            </ParamField>

            <ParamField body="ne" type="integer">
              Không bằng số lượng được chỉ định.
            </ParamField>

            <ParamField body="lt" type="integer">
              Nhỏ hơn số lượng được chỉ định.
            </ParamField>

            <ParamField body="gt" type="integer">
              Lớn hơn số lượng được chỉ định.
            </ParamField>
          </Expandable>
        </ParamField>
      </Expandable>
    </ParamField>

    <ParamField body="nonempty_txn_signature" type="boolean">
      Nếu là `true`, chỉ bao gồm các bản cập nhật do giao dịch gây ra. Nếu là `false`, chỉ bao gồm các bản cập nhật không do giao dịch gây ra. Nếu là `undefined`, bao gồm tất cả bản cập nhật.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="slots" type="object">
  Đăng ký nhận thông tin cập nhật về slot.

  <Expandable title="properties" defaultOpen>
    <ParamField body="filter_by_commitment" type="boolean">
      Lọc slot theo mức cam kết.
    </ParamField>

    <ParamField body="interslot_updates" type="boolean">
      Bao gồm các bản cập nhật trạng thái slot trung gian (PROCESSED, CONFIRMED, FINALIZED,
      FIRST\_SHRED\_RECEIVED, COMPLETED, CREATED\_BANK, DEAD).
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="transactions" type="object">
  Đăng ký nhận thông tin cập nhật về giao dịch.

  <Expandable title="properties" defaultOpen>
    <ParamField body="vote" type="boolean">
      Bao gồm các giao dịch biểu quyết.
    </ParamField>

    <ParamField body="failed" type="boolean">
      Bao gồm các giao dịch thất bại.
    </ParamField>

    <ParamField body="signature" type="string">
      Giám sát một chữ ký giao dịch cụ thể.
    </ParamField>

    <ParamField body="account_include" type="array">
      Chỉ bao gồm các giao dịch ảnh hưởng đến những tài khoản này.
    </ParamField>

    <ParamField body="account_exclude" type="array">
      Loại trừ các giao dịch ảnh hưởng đến những tài khoản này.
    </ParamField>

    <ParamField body="account_required" type="array">
      Giao dịch phải ảnh hưởng đến tất cả các tài khoản này.
    </ParamField>

    <ParamField body="token_accounts" type="enum">
      Tùy chọn mở rộng tài khoản token liên kết (ATA) (thẻ trường 30, `TokenAccountExpansionControlFlag`). Khi được đặt, một ví `account_include` cũng khớp với các giao dịch trong đó ví **sở hữu** số dư token SPL — ví dụ: các lần chuyển token đến tác động đến tài khoản token của ví thay vì khóa công khai của ví. Có hai biến thể:

      * `ALL` (**0**) — khớp với mọi giao dịch tham chiếu đến số dư token mà ví sở hữu, ngay cả khi số dư không thay đổi. Lưu lượng cao hơn.
      * `BALANCE_CHANGED` (**1**) — khớp khi ví sở hữu một số dư token có số lượng thay đổi (hoặc tài khoản token tương ứng bị đóng) trong giao dịch.

      Để tắt tính năng mở rộng, **hãy bỏ hẳn trường này** (`None`) — không có giá trị enum "tắt". Số nguyên nằm ngoài phạm vi sẽ bị từ chối khi tạo cấu hình: `Invalid token_accounts value, expected ALL (0) or BALANCE_CHANGED (1)`.

      <Warning>
        `ALL` là **giá trị không**. Máy khách đặt enum thành `0` với kỳ vọng là "mặc định/tắt" sẽ nhận được `ALL` — chế độ rộng nhất, có lưu lượng cao nhất. Cách duy nhất để biểu thị "không mở rộng" là bỏ hẳn trường này.
      </Warning>
    </ParamField>

    <ParamField body="match_mints" type="boolean" default="false">
      Đồng thời đối chiếu `account_include`, `account_exclude` và `account_required` với các mint trong số dư token trước/sau giao dịch (thẻ trường 32). Đặt một mint vào `account_include` để nhận mọi giao dịch tác động đến token đó, bao gồm cả các lần chuyển SPL thông thường mà khóa tài khoản không bao giờ tham chiếu đến mint. Các giao dịch không có số dư token sẽ quay về chỉ đối chiếu theo khóa. Chỉ riêng `match_mints` không giới hạn luồng; ít nhất một danh sách vẫn phải chứa khóa hoặc mint. Có thể kết hợp với `token_accounts`. Được áp dụng khi phát lại dữ liệu lịch sử. Xem [Lọc theo mint token](/docs/vi/laserstream/mint-filtering).
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="transactions_status" type="object">
  Đăng ký nhận thông tin cập nhật về trạng thái giao dịch.

  <Expandable title="properties" defaultOpen>
    <ParamField body="vote" type="boolean">
      Bao gồm các giao dịch biểu quyết.
    </ParamField>

    <ParamField body="failed" type="boolean">
      Bao gồm các giao dịch thất bại.
    </ParamField>

    <ParamField body="signature" type="string">
      Giám sát một chữ ký giao dịch cụ thể.
    </ParamField>

    <ParamField body="account_include" type="array">
      Chỉ bao gồm các giao dịch ảnh hưởng đến những tài khoản này.
    </ParamField>

    <ParamField body="account_exclude" type="array">
      Loại trừ các giao dịch ảnh hưởng đến những tài khoản này.
    </ParamField>

    <ParamField body="account_required" type="array">
      Giao dịch phải ảnh hưởng đến tất cả các tài khoản này.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="blocks" type="object">
  Đăng ký nhận thông tin cập nhật về khối.

  <Expandable title="properties" defaultOpen>
    <ParamField body="account_include" type="array">
      Chỉ bao gồm các khối có giao dịch ảnh hưởng đến những tài khoản này.
    </ParamField>

    <ParamField body="include_transactions" type="boolean">
      Bao gồm đầy đủ chi tiết giao dịch.
    </ParamField>

    <ParamField body="include_accounts" type="boolean">
      Bao gồm các bản cập nhật tài khoản.
    </ParamField>

    <ParamField body="include_entries" type="boolean">
      Bao gồm các mục nhập của khối.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="blocks_meta" type="object">
  Đăng ký nhận thông tin cập nhật về siêu dữ liệu khối (nhẹ hơn bản cập nhật toàn bộ khối).

  <Expandable title="returns" defaultOpen>
    <ParamField body="slot" type="integer">
      Số slot.
    </ParamField>

    <ParamField body="blockhash" type="string">
      Hàm băm khối.
    </ParamField>

    <ParamField body="rewards" type="array">
      Thông tin phần thưởng.
    </ParamField>

    <ParamField body="block_time" type="integer">
      Thời gian của khối.
    </ParamField>

    <ParamField body="block_height" type="integer">
      Chiều cao khối.
    </ParamField>

    <ParamField body="parent_slot" type="integer">
      Slot cha.
    </ParamField>

    <ParamField body="parent_blockhash" type="string">
      Hàm băm của khối cha.
    </ParamField>

    <ParamField body="executed_transaction_count" type="integer">
      Số lượng giao dịch.
    </ParamField>

    <ParamField body="entries_count" type="integer">
      Số lượng mục nhập.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="entry" type="object">
  Đăng ký nhận thông tin cập nhật về mục nhập.

  <Expandable title="returns" defaultOpen>
    <ParamField body="slot" type="integer">
      Số slot.
    </ParamField>

    <ParamField body="index" type="integer">
      Chỉ mục mục nhập.
    </ParamField>

    <ParamField body="num_hashes" type="integer">
      Số lượng hàm băm.
    </ParamField>

    <ParamField body="hash" type="string">
      Hàm băm.
    </ParamField>

    <ParamField body="executed_transaction_count" type="integer">
      Số lượng giao dịch.
    </ParamField>

    <ParamField body="starting_transaction_index" type="integer">
      Chỉ mục giao dịch bắt đầu.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="commitment" type="enum">
  Mức cam kết cho đăng ký:

  <Expandable title="levels" defaultOpen>
    <ParamField body="PROCESSED" type="integer">
      (0): Được nút hiện tại xử lý.
    </ParamField>

    <ParamField body="CONFIRMED" type="integer">
      (1): Được đại đa số trong cụm xác nhận.
    </ParamField>

    <ParamField body="FINALIZED" type="integer">
      (2): Được cụm hoàn tất.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="accounts_data_slice" type="array">
  Chỉ định phần dữ liệu tài khoản cần nhận:

  <Expandable title="properties" defaultOpen>
    <ParamField body="offset" type="integer">
      Vị trí tính theo byte để bắt đầu đọc dữ liệu.
    </ParamField>

    <ParamField body="length" type="integer">
      Số byte cần đọc.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="ping" type="object">
  Bật thông điệp ping-pong để giám sát trạng thái kết nối.

  <Expandable title="properties" defaultOpen>
    <ParamField body="id" type="integer">
      Mã định danh dạng số cho ping.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="from_slot" type="integer">
  Slot bắt đầu để nhận thông tin cập nhật. Thông tin cập nhật cho các slot trước giá trị này
  sẽ bị loại trừ. Sử dụng [SubscribeReplayInfo](/docs/vi/api-reference/laserstream/grpc/subscribereplayinfo)
  để xác định slot phát lại sớm nhất hiện có trước khi mở đăng ký.
</ParamField>

<RequestExample>
  ```json Accounts Subscription theme={"system"}
  {
    "slots": {
        "slots": {}
    },
    "accounts": {
        "user-defined-label": {
            "account": [
                "DjUF9ASpyMbVpGJmTvzfSbCgUWj6JowwLh8dGAJzSPmu",
                "5U3bH5b6XtG99aVCE9ycvDgBKQx3fVT8WwTNbMToFuEr"
            ],
            "owner": [
                "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
            ],
            "filter": {
                "memcmp": {
                    "offset": 0,
                    "bytes": "0102030405"
                },
                "datasize": 165,
                "token_account_state": true,
                "lamports": {
                    "gt": 100000000
                }
            },
            "nonempty_txn_signature": true
        }
    },
    "transactions": {},
    "blocks": {},
    "blocks_meta": {},
    "accounts_data_slice": [],
    "commitment": 1
  }
  ```

  ```json Slots Subscription theme={"system"}
  {
    "slots": {
      "incoming_slots": {}
    },
    "commitment": 1
  }
  ```

  ```json Transactions Subscription theme={"system"}
  {
    "transactions": {
      "vote": false,
      "failed": true,
      "signature": "4RPMxKBhCBubFmZ1r9BC52ztjG3qBTW9Gp1PXfufUSATQaLKTW3Dj6vQBYyVrhfjgJ4PjZLzwYs4Z92KDCPw8Qym",
      "account_include": ["DjUF9ASpyMbVpGJmTvzfSbCgUWj6JowwLh8dGAJzSPmu"],
      "account_exclude": ["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"],
      "account_required": ["11111111111111111111111111111111"]
    },
    "commitment": 2
  }
  ```

  ```json Wallet + Token Transfers (ATA expansion) theme={"system"}
  {
    "transactions": {
      "wallet": {
        "vote": false,
        "failed": false,
        "account_include": ["DjUF9ASpyMbVpGJmTvzfSbCgUWj6JowwLh8dGAJzSPmu"],
        "account_exclude": [],
        "account_required": [],
        "token_accounts": 1
      }
    },
    "commitment": 1
  }
  ```

  ```json Token Mint Subscription (match_mints) theme={"system"}
  {
    "transactions": {
      "usdc": {
        "vote": false,
        "failed": false,
        "account_include": ["EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"],
        "account_exclude": [],
        "account_required": [],
        "match_mints": true
      }
    },
    "commitment": 1
  }
  ```

  ```json Transaction Status Subscription theme={"system"}
  {
    "transactions_status": {
      "vote": false,
      "failed": true,
      "account_include": ["DjUF9ASpyMbVpGJmTvzfSbCgUWj6JowwLh8dGAJzSPmu"],
      "account_exclude": ["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"],
      "account_required": ["11111111111111111111111111111111"]
    },
    "commitment": 2
  }
  ```

  ```json Blocks Subscription theme={"system"}
  {
    "blocks": {
      "account_include": ["DjUF9ASpyMbVpGJmTvzfSbCgUWj6JowwLh8dGAJzSPmu"],
      "include_transactions": 1,
      "include_accounts": 1,
      "include_entries": 0
    },
    "commitment": 2
  }
  ```

  ```json Block Metadata Subscription theme={"system"}
  {
    "blocks_meta": {},
    "commitment": 2,
    "from_slot": 139000000
  }
  ```

  ```json Entry Subscription theme={"system"}
  {
    "entry": {},
    "commitment": 1
  }
  ```

  ```json Partial Account Data Subscription theme={"system"}
  {
    "accounts": {
      "account": ["DjUF9ASpyMbVpGJmTvzfSbCgUWj6JowwLh8dGAJzSPmu"]
    },
    "accounts_data_slice": [
      {
        "offset": 0,
        "length": 64
      },
      {
        "offset": 128,
        "length": 32
      }
    ],
    "commitment": 2
  }
  ```

  ```json Ping Subscription theme={"system"}
  {
    "ping": {
      "id": 1
    }
  }
  ```

  ```json Combined Subscription theme={"system"}
  {
    "accounts": {
      "account": ["DjUF9ASpyMbVpGJmTvzfSbCgUWj6JowwLh8dGAJzSPmu"],
      "nonempty_txn_signature": true
    },
    "slots": {
      "filter_by_commitment": 1,
      "interslot_updates": 1
    },
    "commitment": 2,
    "from_slot": 139000000,
    "ping": {
      "id": 123
    }
  }
  ```
</RequestExample>

## Mức cam kết

Tất cả đăng ký đều hỗ trợ các mức cam kết sau:

* `PROCESSED`: Được nút hiện tại xử lý (0)
* `CONFIRMED`: Được đại đa số trong cụm xác nhận (1)
* `FINALIZED`: Được cụm hoàn tất (2)

## Cấu trúc phản hồi

Phản hồi đăng ký bao gồm:

* `filters`: Tên các bộ lọc khớp với bản cập nhật này
* Một trong các loại bản cập nhật sau:
  * `account`: Dữ liệu tài khoản, chủ sở hữu, lamport, trạng thái thực thi, v.v.
  * `slot`: Thông tin slot và các bản cập nhật trạng thái
  * `transaction`: Đầy đủ chi tiết giao dịch, chữ ký và siêu dữ liệu
  * `transaction_status`: Trạng thái thực thi giao dịch (thành công/lỗi)
  * `block`: Dữ liệu khối hoàn chỉnh cùng các giao dịch, tài khoản, phần thưởng, v.v.
  * `block_meta`: Siêu dữ liệu khối gọn nhẹ, không có đầy đủ chi tiết giao dịch
  * `entry`: Chi tiết mục nhập trong một khối
  * `ping`/`pong`: Thông điệp kiểm tra trạng thái kết nối
* `created_at`: Dấu thời gian khi bản cập nhật được tạo

<ResponseExample>
  ```json Account Update theme={"system"}
  {
    "filters": ["accounts"],
    "account": {
      "account": {
        "pubkey": "BASE58_ENCODED_PUBKEY",
        "lamports": 12345678,
        "owner": "BASE58_ENCODED_OWNER",
        "executable": false,
        "rent_epoch": 361,
        "data": "BASE64_ENCODED_DATA",
        "write_version": 123,
        "txn_signature": "BASE58_ENCODED_SIGNATURE"
      },
      "slot": 189554321,
      "is_startup": false
    },
    "created_at": "2023-04-28T12:34:56.789Z"
  }
  ```

  ```json Slot Update theme={"system"}
  {
    "filters": ["slots"],
    "slot": {
      "slot": 189554321,
      "parent": 189554320,
      "status": 2,
      "dead_error": null
    },
    "created_at": "2023-04-28T12:34:56.789Z"
  }
  ```

  ```json Transaction Update theme={"system"}
  {
    "filters": ["transactions"],
    "transaction": {
      "transaction": {
        "signature": "BASE58_ENCODED_SIGNATURE",
        "is_vote": false,
        "transaction": {
          "signatures": ["BASE58_ENCODED_SIGNATURE"],
          "message": {
            "header": {
              "num_required_signatures": 1,
              "num_readonly_signed_accounts": 0,
              "num_readonly_unsigned_accounts": 1
            },
            "account_keys": ["BASE58_ENCODED_PUBKEY1", "BASE58_ENCODED_PUBKEY2"],
            "recent_blockhash": "BASE58_ENCODED_BLOCKHASH",
            "instructions": [
              {
                "program_id_index": 1,
                "accounts": [0],
                "data": "BASE64_ENCODED_INSTRUCTION_DATA"
              }
            ]
          }
        },
        "meta": {
          "err": null,
          "fee": 5000,
          "pre_balances": [10000000, 1],
          "post_balances": [9995000, 1],
          "pre_token_balances": [],
          "post_token_balances": [],
          "log_messages": ["Program log: Instruction executed"],
          "rewards": []
        },
        "index": 2
      },
      "slot": 189554321
    },
    "created_at": "2023-04-28T12:34:56.789Z"
  }
  ```

  ```json Block Metadata Update theme={"system"}
  {
    "filters": ["blocks_meta"],
    "block_meta": {
      "slot": 189554321,
      "blockhash": "BASE58_ENCODED_BLOCKHASH",
      "rewards": [
        {
          "pubkey": "BASE58_ENCODED_PUBKEY",
          "lamports": 1785000,
          "post_balance": 48589432109,
          "reward_type": 0,
          "commission": 10
        }
      ],
      "block_time": 1682684096,
      "block_height": 185432109,
      "parent_slot": 189554320,
      "parent_blockhash": "BASE58_ENCODED_PARENT_BLOCKHASH",
      "executed_transaction_count": 2576,
      "entries_count": 16
    },
    "created_at": "2023-04-28T12:34:56.789Z"
  }
  ```

  ```json Entry Update theme={"system"}
  {
    "filters": ["entry"],
    "entry": {
      "slot": 189554321,
      "index": 5,
      "num_hashes": 8765432,
      "hash": "BASE58_ENCODED_HASH",
      "executed_transaction_count": 128,
      "starting_transaction_index": 1024
    },
    "created_at": "2023-04-28T12:34:56.789Z"
  }
  ```

  ```json Pong Response theme={"system"}
  {
    "filters": [],
    "pong": {
      "id": 1
    },
    "created_at": "2023-04-28T12:34:56.789Z"
  }
  ```
</ResponseExample>
