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

# 条目监控

> 使用 Yellowstone gRPC 流式传输低级 Solana 区块条目

## 什么是条目？

条目是 Solana 区块内的基本执行单元。每个区块由一个或多个条目组成，每个条目包含一批按顺序执行的交易。条目代表区块数据的最细粒度级别——低于区块，高于单个交易。

监控条目适用于：

* 构建需要精确交易排序的自定义区块解析器
* 重建区块内的执行顺序
* 在 Slot 内低延迟检测特定交易

<Note>
  对于大多数使用场景，交易或区块订阅更简单。仅当您需要子区块粒度或正在构建直接处理条目的基础设施时（例如自定义账本解析器），才使用条目监控。
</Note>

## 过滤参数

条目订阅不支持基于内容的过滤器——您接收订阅承诺级别的所有条目。唯一的配置是订阅请求中设置的承诺级别。

## 示例：流式传输所有条目

```typescript theme={null}
import Client, { CommitmentLevel, SubscribeRequest } from "@triton-one/yellowstone-grpc";

const client = new Client(
  "https://your-endpoint.grpc.orbitflare.com",
  "YOUR_GRPC_TOKEN",
  { "grpc.max_receive_message_length": 1024 * 1024 * 1024 }
);

async function main() {
  const stream = await client.subscribe();

  const streamClosed = new Promise<void>((resolve, reject) => {
    stream.on("error", (error) => {
      console.error("流错误:", error);
      reject(error);
      stream.end();
    });
    stream.on("end", () => resolve());
    stream.on("close", () => resolve());
  });

  stream.on("data", (data) => {
    if (data.entry) {
      const { slot, index, numHashes, hash, transactions, startingTransactionIndex } = data.entry;
      console.log(`条目 [slot ${slot}, 索引 ${index}]:`);
      console.log(`  哈希: ${Buffer.from(hash).toString("base64")}`);
      console.log(`  哈希数: ${numHashes}`);
      console.log(`  条目中的交易数: ${transactions?.length ?? 0}`);
      console.log(`  起始交易索引: ${startingTransactionIndex}`);
    } else if (data.pong) {
      console.log("收到 Pong");
    }
  });

  const request: SubscribeRequest = {
    entry: {
      entryStream: {},
    },
    commitment: CommitmentLevel.PROCESSED,
    accounts: {},
    accountsDataSlice: [],
    transactions: {},
    transactionsStatus: {},
    slots: {},
    blocks: {},
    blocksMeta: {},
    ping: { id: 1 },
  };

  await new Promise<void>((resolve, reject) => {
    stream.write(request, (err) => {
      if (err == null) resolve(); else reject(err);
    });
  });

  setInterval(() => {
    stream.write({ ping: { id: 1 }, accounts: {}, accountsDataSlice: [], transactions: {}, transactionsStatus: {}, slots: {}, blocks: {}, blocksMeta: {}, entry: {} }, () => {});
  }, 30_000);

  await streamClosed;
}

main();
```

## 条目数据字段

| 字段                         | 类型                       | 描述                     |
| -------------------------- | ------------------------ | ---------------------- |
| `slot`                     | `uint64`                 | 此条目所属的 Slot            |
| `index`                    | `uint64`                 | 此条目在 Slot 内的位置（从 0 开始） |
| `numHashes`                | `uint64`                 | 自上一条目以来的 PoH 哈希数       |
| `hash`                     | `bytes`                  | 此条目的 PoH 哈希            |
| `transactions`             | `ConfirmedTransaction[]` | 此条目中包含的交易              |
| `startingTransactionIndex` | `uint64`                 | 此条目中第一个交易在区块内的索引       |

## 将条目与其他订阅结合使用

条目很少单独订阅。常见模式是将条目订阅与 Slot 订阅结合，以知道 Slot 何时最终确定，然后处理其条目：

```typescript theme={null}
const request: SubscribeRequest = {
  entry: {
    entryStream: {},
  },
  slots: {
    slotUpdates: {
      filterByCommitment: true,
    },
  },
  commitment: CommitmentLevel.CONFIRMED,
  accounts: {},
  accountsDataSlice: [],
  transactions: {},
  transactionsStatus: {},
  blocks: {},
  blocksMeta: {},
};
```

这允许您按 Slot 缓冲条目，并在 Slot 达到目标承诺级别后原子性地处理它们。
