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

# Trade on Preconfirmations

> React to Solana transactions before they land: subscribe to preconfSubscribe filters, decode the binary payload, and act with Sender Max.

[Preconfirmations](https://www.helius.dev/docs/pre-confirmations/overview.md) stream transactions before they are shredded — Helius preconfirmations the instant the leader executes them, together with their execution status. This guide builds a listener that watches a target account, decodes each transaction, and reacts using [Sender Max](https://www.helius.dev/docs/sending-transactions/sender-max.md).

> [!TIP]
>
> Preconfirmations are available on [all paid plans](https://www.helius.dev/docs/billing/plans.md) and cost 10 credits per delivered message. Slots with zero delivered messages cost zero credits. When a slot delivers at least one message, each subscription has a 300-credit minimum. See [Pricing](https://www.helius.dev/docs/pre-confirmations/overview.md#pricing).

## Scope the stream before you connect

An unfiltered `preconfSubscribe` delivers every transaction at 10 credits each. Filter server-side to cut the bill down to the transactions you trade on. Each subscription is billed independently when it receives at least one message in an eligible covered slot, so consolidate account filters into one subscription where practical. Use `regionInclude` to limit billing to the regions you need, set `includeSource: ["helius"]` when you do not need BAM, and monitor credits in the [Helius Dashboard](https://dashboard.helius.dev).

```json theme={"system"}
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "preconfSubscribe",
  "params": [
    {
      "includeSource": ["helius"],
      "failed": false,
      "regionInclude": ["ewr"],
      "accountInclude": ["TARGET_WALLET_OR_PROGRAM"]
    }
  ]
}
```

Three filters cover most trading listeners:

* `failed: false` drops transactions already known to have reverted, which you have no reason to race.
* `regionInclude` pins the stream to the [region](https://www.helius.dev/docs/pre-confirmations/preconf-subscribe.md#location-filtering) closest to your infrastructure, so a cross-region hop doesn't eat the head start.
* `accountInclude` matches any tx referencing your target: a wallet, AMM pool, program, etc. Helius resolves address lookup tables server-side, so the filter matches even when the account is loaded through an ALT.

## Connect, subscribe, and decode

`preconfSubscribe` is served from the Gatekeeper endpoint (`wss://beta.helius-rpc.com`), and notifications arrive as binary frames, not JSON.

Each frame is a fixed 18-byte prefix followed by the bincode-serialized transaction:

```javascript listener.js theme={"system"}
const WebSocket = require('ws');
const { VersionedTransaction } = require('@solana/web3.js');

const ws = new WebSocket('wss://beta.helius-rpc.com/?api-key=YOUR_API_KEY');

ws.on('open', () => {
  ws.send(JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'preconfSubscribe',
    params: [{
      failed: false,
      regionInclude: ['ewr'],
      accountInclude: ['TARGET_WALLET_OR_PROGRAM']
    }]
  }));
  setInterval(() => ws.ping(), 30_000); // keep the connection alive
});

ws.on('message', (data, isBinary) => {
  if (!isBinary) {
    const msg = JSON.parse(data.toString());
    if (msg.id === 1) console.log('Subscribed, ID:', msg.result);
    return;
  }

  // version (u8) | slot (u64 LE) | tx_index (u64 LE) | status (u8) | bincode(VersionedTransaction)
  const buf = Buffer.from(data);
  if (buf.readUInt8(0) !== 1) return; // unknown schema version; update your decoder
  const slot = buf.readBigUInt64LE(1);
  const status = buf.readUInt8(17); // 0 = failed, 1 = success, 2 = unknown
  const tx = VersionedTransaction.deserialize(buf.subarray(18));

  onScheduledTransaction({ slot, status, tx });
});

ws.on('error', console.error);
ws.on('close', () => process.exit(1)); // let your supervisor restart and resubscribe
```

Check the version byte first. If Helius updates the payload format, the version increments, and branching on it keeps your decoder working. The deserialized transaction gives you the instructions, accounts, and signature.

## Act with Sender Max

A preconfirmation only pays off if your response lands first.

Send your reaction through [Sender Max](https://www.helius.dev/docs/sending-transactions/sender-max.md): the 0.001 SOL tip enters the priority tip buffer and routes across every high-speed pathway:

```javascript theme={"system"}
async function onScheduledTransaction({ slot, status, tx }) {
  if (!strategy.shouldReact(tx)) return;

  // strategy is your own code: it decides whether to react and returns a
  // signed, base64-encoded transaction that includes the tip and priority fee
  const reaction = await strategy.buildTransaction(tx);
  await fetch('http://ewr-sender.helius-rpc.com/fast', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      jsonrpc: '2.0',
      id: Date.now().toString(),
      method: 'sendTransaction',
      params: [reaction, { encoding: 'base64', skipPreflight: true, maxRetries: 0 }]
    })
  });
}
```

Keep this handler short. Decide and send, and move logging, accounting, and reconciliation off the receive path. See [Land Trades with Sender](https://www.helius.dev/docs/sending-transactions/guides/land-trades-with-sender.md) for the full send loop, including connection warming and fee estimation.

## Confirm landing and expect gaps

A preconfirmation is an early look. The transaction has not landed yet and can still fail or be dropped, so two rules apply:

* Confirm through standard commitment checks (`getSignatureStatuses`, or a `processed`-commitment stream) before treating either the observed transaction or your reaction as final.
* Expect gaps. Coverage scales with the share of stake forwarding to Helius, so some slots produce no messages. That is [expected behavior](https://www.helius.dev/docs/pre-confirmations/overview.md#coverage) rather than a dead connection, and the keepalive ping tells the two apart. Resubscribe on close.

## Related guides

> [card] [preconfSubscribe API reference](https://www.helius.dev/docs/pre-confirmations/preconf-subscribe.md)
>
> Full filter semantics, region codes, and the binary payload layout

> [card] [Trade on Preprocessed Transactions](https://www.helius.dev/docs/preprocessed-transactions/guides/trade-on-preprocessed.md)
>
> Pre-execution coverage at 0.1 credits per message, on all paid plans


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.