> ## 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](/docs/pre-confirmations/overview) stream transactions the instant a validator's scheduler commits to executing them, before they are shredded. This guide builds a listener that watches a target account, decodes each scheduled transaction, and reacts using [Sender Max](/docs/sending-transactions/sender-max).

<Tip>
  Preconfirmations require a [Professional plan or higher](/docs/billing/plans) and cost 10 credits per message.
</Tip>

## Scope the stream before you connect

An unfiltered `preconfSubscribe` delivers every scheduled transaction at 10 credits each, so filter server-side and pay only for what you trade on.

```json theme={"system"}
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "preconfSubscribe",
  "params": [
    {
      "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](/docs/pre-confirmations/preconf-subscribe#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](/docs/sending-transactions/sender-max): 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](/docs/sending-transactions/guides/land-trades-with-sender) 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](/docs/pre-confirmations/overview#coverage) rather than a dead connection, and the keepalive ping tells the two apart. Resubscribe on close.

## Related guides

<CardGroup cols={2}>
  <Card title="preconfSubscribe API reference" icon="code" href="/docs/pre-confirmations/preconf-subscribe">
    Full filter semantics, region codes, and the binary payload layout
  </Card>

  <Card title="Trade on Preprocessed Transactions" icon="bolt" href="/docs/preprocessed-transactions/guides/trade-on-preprocessed">
    Pre-execution coverage at 0.1 credits per message, on all paid plans
  </Card>
</CardGroup>
