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

# accountSubscribe 사용 방법

> `accountSubscribe`를 사용하여 Solana 계정의 실시간 업데이트를 스트리밍하십시오. 잔액 변경, 데이터 수정 및 램포트 업데이트를 WebSocket을 통해 모니터링합니다.

## `accountSubscribe`란 무엇인가?

Solana의 WebSockets는 계정에 구독하고 해당 계정 공개 키와 관련된 램포트 또는 데이터에 변경 사항이 있을 때마다 WebSocket 연결을 통해 알림을 받을 수 있는 메서드를 지원합니다.

이 메서드는 [Solana WSS API 사양](https://solana.com/docs/rpc/websocket#accountsubscribe)에 직접적으로 부합합니다.

## 매개변수

* `string`: `base58` 형식으로 보내지는 계정 공개 키 (필수)
* `object`: 추가 매개변수를 전달하는 데 사용되는 선택적 객체
* `encoding`: `AccountNotification`에서 반환되는 데이터의 형식을 지정. 지원되는 값: `base58` (기본값), `base64`, `base64+zstd`, `jsonParsed`
* `commitment`: 거래에 대한 커밋 수준을 정의. 지원되는 값: `finalized` (기본값), `confirmed`, `processed`
* `notifyOn`: Helius 전용. `"write"`로 설정하여 거래가 계정에 실제로 쓰기 작업을 할 때만 알림을 받습니다 (동일한 데이터를 쓰는 것도 포함). 기본값 `"lock"`는 거래가 계정을 쓰기 잠근 경우에도 알림을 보냅니다. [notifyOn 필터링](/docs/ko/rpc/websocket/notify-on-filtering)을 참조하십시오.

## 계정 구독 예시

이 예에서는 계정 `SysvarC1ock11111111111111111111111111111111`에 대한 변경 사항을 구독하고 있습니다.

이 계정의 데이터나 램포트에 변경이 있을 때마다 업데이트를 받을 수 있습니다.

특정 계정에 대해 이것은 자주 발생합니다. `slot` 및 `unixTimestamp`가 반환된 계정 데이터에 모두 포함되어 있기 때문입니다.

<Tip>
  Helius의 필터링된 `accountSubscribe`는 다른 WebSocket 구독 메서드와 동일한 통합된 `wss://mainnet.helius-rpc.com` 및 `wss://devnet.helius-rpc.com` [엔드포인트](https://www.helius.dev/docs/api-reference/endpoints)에 존재합니다.
</Tip>

<CodeGroup>
  ```javascript theme={"system"}
  const WebSocket = require('ws');

  // Create a WebSocket connection
  const ws = new WebSocket('wss://mainnet.helius-rpc.com?api-key=<API_KEY>');

  // Function to send a request to the WebSocket server
  function sendRequest(ws) {
      const request = {
          jsonrpc: "2.0",
          id: 420,
          method: "accountSubscribe",
          params: [
              "SysvarC1ock11111111111111111111111111111111", // pubkey of account we want to subscribe to
              {
                  encoding: "jsonParsed", // base58, base64, base64+zstd, jsonParsed
                  commitment: "confirmed", // defaults to finalized if unset
                  // notifyOn: "write", // Helius-specific: skip updates where the account was locked but never written to
              }
          ]
      };
      ws.send(JSON.stringify(request));
  }

  // Function to send a ping to the WebSocket server
  function startPing(ws) {
      setInterval(() => {
          if (ws.readyState === WebSocket.OPEN) {
              ws.ping();
              console.log('Ping sent');
          }
      }, 30000); // Ping every 30 seconds
  }

  // Define WebSocket event handlers

  ws.on('open', function open() {
      console.log('WebSocket is open');
      sendRequest(ws);  // Send a request once the WebSocket is open
      startPing(ws);    // Start sending pings
  });

  ws.on('message', function incoming(data) {
      const messageStr = data.toString('utf8');
      try {
          const messageObj = JSON.parse(messageStr);
          console.log('Received:', messageObj);
      } catch (e) {
          console.error('Failed to parse JSON:', e);
      }
  });

  ws.on('error', function error(err) {
      console.error('WebSocket error:', err);
  });

  ws.on('close', function close() {
      console.log('WebSocket is closed');
  });
  ```
</CodeGroup>

### 알림 예시

<CodeGroup>
  ```json theme={"system"}
  {
      "jsonrpc": "2.0",
      "method": "accountNotification",
      "params": {
          "subscription": 237508762798666,
          "result": {
              "context": {"slot": 235781083},
              "value": {
                  "lamports": 1169280,
                  "data": "BvEhEb6hixL3QPn41gHcyi2CDGKt381jbNKFFCQr6XDTzCTXCuSUG9D",
                  "owner": "Sysvar1111111111111111111111111111111111111",
                  "executable": false,
                  "rentEpoch": 361,
                  "space": 40
              }
          }
      }
  }
  ```
</CodeGroup>
