跳转到主要内容

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.

安装

npm install @orbitflare/sdk @grpc/grpc-js yaml
@grpc/grpc-jsyaml 为可选对等依赖。仅在使用 JetStream(或 YAML 配置)时才需要安装。

构建客户端

import { JetstreamClientBuilder, type RetryPolicy } from '@orbitflare/sdk';

const client = new JetstreamClientBuilder()
  .url('http://ny.jetstream.orbitflare.com')
  .fallbackUrl('http://fra.jetstream.orbitflare.com')
  .retry({
    initialDelayMs: 100,
    maxDelayMs: 30_000,
    multiplier: 2.0,
    maxAttempts: 0,
  })
  .timeoutSecs(30)
  .keepaliveSecs(60)
  .pingIntervalSecs(10)
  .maxMissedPongs(3)
  .channelCapacity(4096)
  .build();
最简配置:
const client = new JetstreamClientBuilder()
  .url('http://ny.jetstream.orbitflare.com')
  .build();
URL 回退读取环境变量 ORBITFLARE_JETSTREAM_URL。所有构建器方法与 gRPC 客户端 相同 - 默认与行为一致。

编写 YAML 配置

JetStream 支持交易与账户过滤器。不包含槽位、区块或承诺 - 这些为 Yellowstone 专有。
# jetstream.yml
transactions:
  raydium:
    account_include:
      - "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"
  pumpfun:
    account_include:
      - "6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P"

accounts:
  my_wallet:
    account:
      - "YOUR_WALLET_ADDRESS"
    owner:
      - "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"

YAML 过滤器参考

transactions - 命名过滤器。account_include 匹配涉及这些地址的交易。account_exclude 排除匹配。account_required 表示所列地址必须全部出现。 accounts - 使用 account 监视特定地址,或使用 owner 监视某程序拥有的全部账户。 支持 ${ENV_VAR} 展开。

订阅与读取事件

自 YAML

const stream = client.subscribeYaml('jetstream.yml');

编程方式

import { proto } from '@orbitflare/sdk';

const request: proto.jetstream.SubscribeRequest = {
  transactions: {
    target: {
      accountInclude: [someAddress],
      accountExclude: [],
      accountRequired: [],
    },
  },
  accounts: {},
  ping: { id: 1 },
};

const stream = client.subscribe(request);

读取流

for await (const update of stream) {
  if (update.transaction) {
    // update.transaction.slot - the slot number
    // update.transaction.transaction - transaction info with signature, accountKeys,
    //   instructions, addressTableLookups
  } else if (update.account) {
    // update.account.slot - the slot
    // update.account.account - account info (pubkey, lamports, owner, data)
    // update.account.isStartup - true during initial snapshot
  }
}
关闭、多流、重连与 ping/pong 行为与 gRPC 客户端 完全一致。

完整示例

监听 Raydium AMM swap 并打印每条交易的签名与指令数量:
import bs58 from 'bs58';
import { JetstreamClientBuilder } from '@orbitflare/sdk';

async function main() {
  const client = new JetstreamClientBuilder()
    .url('http://ny.jetstream.orbitflare.com')
    .build();

  const stream = client.subscribeYaml('jetstream.yml');
  let count = 0;

  console.log('streaming raydium txs...');

  for await (const update of stream) {
    if (update.transaction) {
      count += 1;
      const info = update.transaction.transaction;
      if (info?.signature) {
        const sig = bs58.encode(info.signature);
        const numIx = info.instructions.length;
        const numAccounts = info.accountKeys.length;
        console.log(
          `#${count} slot=${update.transaction.slot} sig=${sig.slice(0, 16)}... ix=${numIx} accounts=${numAccounts}`,
        );
      }
    }
  }
}

void main();
配合以下 jetstream.yml
transactions:
  raydium:
    account_include:
      - "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"