Subscriptions

This document covers all subscription methods and filtering options available in ThorPulse.

Simple Subscriptions

Simple subscriptions connect directly to NATS topic patterns. They're easy to use but don't support server-side filtering.

Slots

Go
// All slot updates
slots := client.SubscribeSlotsChannel(ctx)

// Confirmed slots only
slots := client.SubscribeSlotsConfirmedChannel(ctx)

Topic patterns:

  • slots.> - All slot events

  • slots.*.confirmed - Confirmed slots only

  • slots.*.finalized - Finalized slots only

  • slots.{slot_number}.{status} - Specific slot

Transactions

Go
// All transactions (high volume!)
txs := client.SubscribeAllTransactionsChannel(ctx)

// By program
txs := client.SubscribeProgramChannel(ctx, "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8")

// By account
txs := client.SubscribeAccountTransactionsChannel(ctx, pubkey)

Topic patterns:

  • txs.slot.> - All transactions

  • txs.program.{program_id}.> - By program

  • txs.account.{pubkey}.> - By account

  • txs.sig.{signature}.{slot} - Specific transaction

Entries

Topic patterns:

  • entries.> - All entries

  • entries.{slot}.{index} - Specific entry

Accounts

Topic patterns:

  • accounts.> - All account updates

  • accounts.pubkey.{pubkey}.{slot} - Specific account

  • accounts.owner.{program}.{slot} - By owner program

SubscribeRequest (Yellowstone-Style)

SubscribeRequest enables server-side filtering, reducing bandwidth and latency. It's the recommended approach for production.

Basic Usage

Filter Types

Slot Filter

Transaction Filter

Field
Type
Description

Vote

*bool

true=votes only, false=non-votes only

Failed

*bool

true=failed only, false=successful only

Signature

string

Filter for specific signature

AccountInclude

[]string

Include if ANY account present

AccountExclude

[]string

Exclude if ANY account present

AccountRequired

[]string

Require ALL accounts present

Account Filter

Filter
Description

Datasize

Match exact account data size

Memcmp

Match bytes at offset

TokenAccountState

Only valid SPL token accounts

Lamports.Eq

Exact lamport balance

Lamports.Ne

Not equal to balance

Lamports.Lt

Less than balance

Lamports.Gt

Greater than balance

Entry Filter

Entries don't have filter options - you receive all entries or none.

Block Filter

Block Meta Filter

Block metadata is lighter than full blocks - contains slot, blockhash, parent, rewards summary.

Commitment Levels

Level
Description
Use Case

Processed

Transaction processed by leader

Real-time display

Confirmed

Confirmed by supermajority

Trading, analytics

Finalized

Guaranteed irreversible

Settlement, accounting

Handling Updates

Go Handler Pattern

Rust Stream Pattern

Performance Considerations

Subscription Limits

Each tier has subscription limits:

  • Flash: 100 concurrent subscriptions

  • Thor: 250 concurrent subscriptions

  • Prime: Unlimited

Topic Selection

Start specific, widen if needed:

1

Specific account/program subscriptions

Lowest bandwidth: subscribe to specific accounts or programs.

2

SubscribeRequest with filters

Server-side filtering reduces client bandwidth and latency.

3

Simple topic subscriptions

Client-side filtering on topic subscriptions; broader than filtered SubscribeRequest.

4

Wildcard subscriptions

Highest bandwidth: use only when you need broad coverage.

Buffer Sizing

For high-volume subscriptions:

Backpressure

If you can't keep up:

1

The NATS connection buffers messages

This provides temporary buffering while you catch up.

2

Eventually, slow consumers are disconnected

If buffers overflow or consumers are too slow, NATS will disconnect them.

3

Use client.Stats() to monitor buffer usage

Monitor and react programmatically to growing buffers.

Common Patterns

DEX Trading

Token Monitoring

Wallet Tracking

Last updated