stream.mts。以下示例使用相同的环境变量与依赖。
订阅 slot 与区块元数据
slots.mts
filterByCommitment: true 将 slot 通知与请求的确认级别对齐。一个 slot 可有多个状态更新,记录变化时同时保存 slot 与状态。
请求筛选后的区块
filtered-blocks.mts
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
选择 slot 更新、区块元数据或筛选后的区块数据,跟踪确认状态并处理数据间隔。
stream.mts。以下示例使用相同的环境变量与依赖。
import { subscribe } from "./stream.mts";
for await (const update of subscribe({
slots: { slots: { filterByCommitment: true } },
blocksMeta: { blocks: {} },
})) {
if (update.slot) {
console.log("slot", update.slot.slot, update.slot.parent, update.slot.status);
}
if (update.blockMeta) {
console.log("block", update.blockMeta.slot, update.blockMeta.blockhash,
update.blockMeta.executedTransactionCount);
}
}
npx tsx slots.mts
filterByCommitment: true 将 slot 通知与请求的确认级别对齐。一个 slot 可有多个状态更新,记录变化时同时保存 slot 与状态。
import { subscribe } from "./stream.mts";
const address = process.env.WATCH_ADDRESS;
if (!address) throw new Error("Set WATCH_ADDRESS");
for await (const update of subscribe({
blocks: {
selected: {
accountInclude: [address],
includeTransactions: true,
includeAccounts: false,
includeEntries: false,
},
},
})) {
if (!update.block) continue;
console.log(update.block.slot, update.block.transactions.length);
}
此页面对您有帮助吗?