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

# JetStream Client

> OrbitFlare's decoded shreds delivered as gRPC streams with transaction and account filters.

## Install

```bash theme={null}
npm install @orbitflare/sdk @grpc/grpc-js yaml
```

`@grpc/grpc-js` and `yaml` are optional peer dependencies. Install them only if you use JetStream (or YAML config).

## Building the client

```ts theme={null}
import { JetstreamClientBuilder } from '@orbitflare/sdk/jetstream';
import 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();
```

Minimal:

```ts theme={null}
const client = new JetstreamClientBuilder()
  .url('http://ny.jetstream.orbitflare.com')
  .build();
```

URL falls back to `ORBITFLARE_JETSTREAM_URL` env var. All builder methods are identical to the [gRPC client](/sdk/typescript-grpc) - same defaults, same behavior.

## Writing a YAML config

JetStream supports transaction and account filters. No slots, blocks, or commitment - those are Yellowstone-specific.

```yaml theme={null}
# jetstream.yml
transactions:
  raydium:
    account_include:
      - "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"
  pumpfun:
    account_include:
      - "6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P"

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

### YAML filter reference

**`transactions`** - named filters. `account_include` matches transactions involving those addresses. `account_exclude` removes matches. `account_required` means all listed addresses must appear.

**`accounts`** - watch specific addresses with `account`, or all accounts owned by a program with `owner`.

Supports `${ENV_VAR}` expansion.

## Subscribing and reading events

### From YAML

```ts theme={null}
const stream = client.subscribeYaml('jetstream.yml');
```

### Programmatically

```ts theme={null}
import { proto } from '@orbitflare/sdk/proto';

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

const stream = client.subscribe(request);
```

### Reading the stream

```ts theme={null}
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
  }
}
```

Closing, multiple streams, reconnection, and ping/pong all work identically to the [gRPC client](/sdk/typescript-grpc).

## Full example

A stream that watches Raydium AMM swaps and prints each transaction's signature and instruction count.

```ts theme={null}
import bs58 from 'bs58';
import { JetstreamClientBuilder } from '@orbitflare/sdk/jetstream';

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();
```

With this `jetstream.yml`:

```yaml theme={null}
transactions:
  raydium:
    account_include:
      - "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"
```
