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

# getBlocksWithLimit 사용 방법

> getBlocksWithLimit 사용 사례, 코드 예제, 요청 매개변수, 응답 구조 및 팁을 배웁니다.

[`getBlocksWithLimit`](https://www.helius.dev/docs/api-reference/rpc/http/getblockswithlimit) RPC 메서드는 지정된 슬롯에서 시작하여 주어진 제한까지 확정된 블록 슬롯 번호 목록을 검색할 수 있게 합니다. 이는 원장 내 특정 지점에서 후속 확정 [블록](https://www.helius.dev/blog/solana-slots-blocks-and-epochs)이 필요한 경우 유용합니다.

<Warning>
  **더 나은 성능을 위해 배칭을 피하세요**

  배칭 아카이브 방법은 지연 시간을 크게 증가시킵니다. 10개 이상의 요청 배치는 허용되지 않습니다.
</Warning>

## 일반적인 사용 사례

* **후속 블록의 고정된 수 가져오기:** 특정 시작 슬롯 이후에 확정된 블록 슬롯의 정의된 수를 가져옵니다.
* **페이지네이션된 블록 탐색:** 블록체인의 일부를 분석할 때 블록을 부분적으로 수집합니다.
* **최근 블록 모니터링:** 최근 슬롯에서 마지막 N 블록을 가져옵니다.

## 요청 매개변수

`getBlocksWithLimit` 메서드는 다음 매개변수를 사용합니다:

1. **`start_slot`** (u64, 필수): 고려할 첫 번째 슬롯(포함).
2. **`limit`** (u64, 필수): 반환할 최대 블록 슬롯 수. 쿼리된 총 슬롯 수(`start_slot`부터 `limit` 이후의 블록까지)는 **500,000 슬롯을 초과할 수 없습니다**.
3. **`commitment`** (문자열, 선택 사항): 쿼리에 대한 커밋 수준을 지정합니다. 생략할 경우 기본 노드의 커밋을 사용합니다. 이 매개변수는 구성 개체의 유일한 필드로 마지막 매개변수로 전달됩니다.

## 응답 구조

JSON-RPC 응답의 `result` 필드는 u64 정수의 배열이 될 것입니다. 배열의 각 정수는 확정된 블록 슬롯 번호를 나타내며, `start_slot`부터 지정된 `limit`까지 계속됩니다.

* 예: `start_slot`이 5이고 `limit`이 3인 경우 가능한 결과는 `[5, 6, 7]`입니다.

## 예제

### 1. 시작 슬롯에서 제한된 수의 블록 가져오기

이 예제는 슬롯 `280000000`에서 시작하여 최대 5개의 확정된 블록 슬롯 목록을 가져옵니다.

<CodeGroup>
  ```bash cURL theme={"system"}
  curl https://mainnet.helius-rpc.com/?api-key=<api-key> -X POST -H "Content-Type: application/json" -d \
    '{
      "jsonrpc": "2.0",
      "id": 1,
      "method": "getBlocksWithLimit",
      "params": [
        280000000, 
        5 
      ]
    }'
  ```

  ```javascript JavaScript (using @solana/web3.js) theme={"system"}
  const { Connection } = require('@solana/web3.js');

  async function getBlocksWithLimitExample(startSlot, limit) {
    const connection = new Connection('https://mainnet.helius-rpc.com/?api-key=<api-key>');
    try {
      const blocks = await connection.getBlocksWithLimit(startSlot, limit);
      console.log(`Up to ${limit} confirmed blocks starting from slot ${startSlot}:`, blocks);
    } catch (error) {
      console.error('Error fetching blocks with limit:', error);
    }
  }

  // Example usage:
  const startSlot = 280000000;
  const limit = 5;
  getBlocksWithLimitExample(startSlot, limit);
  ```
</CodeGroup>

### 2. 특정 커밋 수준과 함께 블록 가져오기

이 예제는 슬롯 `290000000`에서 시작하여 `confirmed` 커밋 수준을 사용하여 최대 3개의 블록을 가져옵니다.

<CodeGroup>
  ```bash cURL theme={"system"}
  curl https://mainnet.helius-rpc.com/?api-key=<api-key> -X POST -H "Content-Type: application/json" -d \
    '{
      "jsonrpc": "2.0",
      "id": 1,
      "method": "getBlocksWithLimit",
      "params": [
        290000000,
        3,
        { "commitment": "confirmed" }
      ]
    }'
  ```

  ```javascript JavaScript (using @solana/web3.js) theme={"system"}
  const { Connection } = require('@solana/web3.js');

  async function getBlocksWithLimitAndCommitment(startSlot, limit) {
    const connection = new Connection('https://mainnet.helius-rpc.com/?api-key=<api-key>');
    try {
      const blocks = await connection.getBlocksWithLimit(startSlot, limit, { commitment: 'confirmed' });
      console.log(`Up to ${limit} confirmed blocks (with 'confirmed' commitment) starting from slot ${startSlot}:`, blocks);
    } catch (error) {
      console.error('Error fetching blocks with limit and commitment:', error);
    }
  }

  // Example usage:
  const commitStartSlot = 290000000;
  const commitLimit = 3;
  getBlocksWithLimitAndCommitment(commitStartSlot, commitLimit);
  ```
</CodeGroup>

## 개발자 팁

* **범위 명확화:** `limit` 매개변수는 반환할 최대 블록 *슬롯* 수를 결정합니다. 500,000 슬롯 제한은 개념적으로 스캔한 범위에 적용됩니다(즉, `start_slot`에서 `start_slot + limit - 1`까지). 이 개념적 범위가 500,000 슬롯을 초과하지 않도록 하세요. 해당 범위 내에서 찾고 반환되는 실제 블록 수가 적더라도 말입니다.
* **노드 데이터 가용성:** 노드가 모든 역사적 슬롯에 대한 정보를 보유하지 않을 수 있습니다. 매우 오래된 `start_slot`은 지정된 `limit`보다 적은 블록을 반환하거나 노드의 원장 보유에 따라 빈 배열을 반환할 수 있습니다.
* **블록 확인:** 이 메서드는 *확정된* 블록을 반환합니다. 선택한 `commitment` 수준과 쿼리하는 노드에 따라 정확한 블록 집합이 약간 다를 수 있으며, 특히 매우 최근 슬롯의 경우에는 더욱 그렇습니다.
* **사용 사례 특이성:** `getBlocksWithLimit`는 시작점을 알고 후속 블록의 고정 수가 필요한 경우 이상적입니다. 알려진 슬롯 범위 내의 모든 블록이 필요한 경우 `getBlocks`가 더 적절할 수 있습니다.

이 가이드는 Solana 네트워크에서 확정된 블록 슬롯의 특정 수를 나열하기 위해 `getBlocksWithLimit` RPC 메서드를 사용하는 방법에 대한 명확한 개요를 제공합니다.

## 관련 메서드

<CardGroup cols={2}>
  <Card title="getBlocks" href="/docs/ko/api-reference/rpc/http/getblocks">
    슬롯 범위 내의 모든 블록 가져오기
  </Card>

  <Card title="getBlock" href="/docs/ko/api-reference/rpc/http/getblock">
    특정 블록에 대한 자세한 정보 가져오기
  </Card>
</CardGroup>
