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

# 사전 확인으로 거래하기

> "Solana 거래가 착지하기 전에 반응하십시오: preconfSubscribe 필터를 구독하고, 이진 페이로드를 디코딩하고, Sender Max로 행동하십시오."

[사전 확인](/docs/ko/pre-confirmations/overview)은 검증자의 스케줄러가 거래 실행을 확약하는 즉시 거래를 스트리밍하며, 이들이 파편화되기 전입니다. 이 가이드는 대상 계정을 감시하고 각각의 예약된 거래를 디코딩하며 [Sender Max](/docs/ko/sending-transactions/sender-max)를 사용하여 반응하는 리스너를 구축합니다.

<Tip>
  사전 확인은 [프로페셔널 플랜 이상](/docs/ko/billing/plans)이 필요하며 메시지당 10 크레딧이 소요됩니다.
</Tip>

## 연결하기 전에 스트림 범위 지정

필터링되지 않은 `preconfSubscribe`는 각 거래에 대해 10 크레딧으로 모든 예약된 거래를 제공합니다. 따라서 서버 측에서 필터링하고 거래하는 것에 대해서만 비용을 지불하십시오.

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

세 가지 필터가 대부분의 거래 리스너를 다룹니다:

* 이미 반환된 것으로 알려진 거래를 삭제하는 `failed: false`는 레이싱할 이유가 없습니다.
* STREAM을 인프라에 가장 가까운 [지역](/docs/ko/pre-confirmations/preconf-subscribe#위치-필터링)으로 고정하는 `regionInclude`는 교차 지역 홉으로 인해 초기 시작이 소모되지 않도록 합니다.
* 지갑, AMM 풀, 프로그램 등 대상에 대한 모든 TX를 일치시키는 `accountInclude`는 서버 측에서 주소 조회 테이블을 해결하므로 계정이 ALT를 통해 로드되더라도 필터가 일치합니다.

## 연결, 구독, 디코드

`preconfSubscribe`는 게이트키퍼 엔드포인트(`wss://beta.helius-rpc.com`)에서 제공되며, 알림은 JSON이 아닌 이진 프레임으로 도착합니다.

각 프레임은 고정된 18바이트 프리픽스와 바이너리로 직렬화된 거래로 구성되어 있습니다:

```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
```

버전 바이트를 먼저 확인하십시오. Helius가 페이로드 형식을 업데이트하면 버전이 증가하며, 이를 분기하여 디코더가 작동하도록 유지합니다. 직렬화된 거래는 명령, 계정 및 서명을 제공합니다.

## Sender Max로 행동하기

사전 확인은 응답이 먼저 착지할 때만 효과가 있습니다.

귀하의 반응을 [Sender Max](/docs/ko/sending-transactions/sender-max)를 통해 보내십시오: 0.001 SOL 팁이 우선 순위 팁 버퍼로 들어가고 모든 고속 경로로 라우팅됩니다:

```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 }]
    })
  });
}
```

이 핸들러를 짧게 유지하십시오. 결정하고 보내며 로깅, 회계 및 조정을 수신 경로에서 제거하십시오. 전체 전송 루프, 연결 예열, 수수료 추정을 포함하여 [Sender로 거래 착지](/docs/ko/sending-transactions/guides/land-trades-with-sender)를 참조하십시오.

## 착지를 확인하고 간격을 예상하기

사전 확인은 조기 확인입니다. 거래가 아직 착지되지 않았으며 실패하거나 삭제될 수 있으므로 두 가지 규칙이 적용됩니다:

* 표준 커밋 검사를 통해 확인하십시오(`getSignatureStatuses`, 또는 `processed`-커밋 스트림) 관찰된 거래나 귀하의 반응을 최종적으로 처리하기 전에.
* 간격을 예상하십시오. Helius로 포워딩되는 지분의 비율과 함께 범위가 확장되므로 일부 슬롯은 메시지를 생성하지 않습니다. 이는 [예상 동작](/docs/ko/pre-confirmations/overview#커버리지)이며, 두 상태를 구분하는 keepalive ping이 있으며, 닫힐 때 다시 구독하십시오.

## 관련 가이드

<CardGroup cols={2}>
  <Card title="preconfSubscribe API 참조" icon="code" href="/docs/ko/pre-confirmations/preconf-subscribe">
    전체 필터 의미론, 지역 코드 및 이진 페이로드 레이아웃
  </Card>

  <Card title="사전 처리된 거래에서 거래하기" icon="bolt" href="/docs/ko/preprocessed-transactions/guides/trade-on-preprocessed">
    모든 유료 플랜에서 메시지당 0.1 크레딧의 사전 실행 범위
  </Card>
</CardGroup>
