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

# getMinimumBalanceForRentExemptionの使い方

> getMinimumBalanceForRentExemptionの使用例、コード例、リクエストパラメータ、レスポンス構造、ヒントを学ぶ。

この[`getMinimumBalanceForRentExemption`](https://www.helius.dev/docs/api-reference/rpc/http/getminimumbalanceforrentexemption) RPCメソッドを使用すると、特定のデータサイズのアカウントが家賃免除を受けるために必要な最低ラポート残高を計算できます。

Solanaでは、アカウントは長期間のストレージコストをカバーするために最低残高を維持する必要があります。この概念は"レント"として知られています。2年間の家賃支払いに相当する残高を保持しているアカウントは「家賃免除」と見なされ、その残高は[家賃](https://www.helius.dev/blog/solana-executive-overview)によって消耗されません。

## 一般的な使用例

* **アカウントの作成:** 新しいアカウント（例：新しいトークンアカウント、プログラム派生アドレス、カスタムデータストレージ用）を作成する前に、このメソッドを使用して、最初から家賃免除にするために必要なラポートを決定します。これにより、残高が低くなりすぎた場合にアカウントがガベージコレクトされるのを防ぎます。
* **動的アカウントサイズの調整:** アプリケーションがデータサイズが成長する可能性のあるアカウントを扱う場合、このメソッドを使用して、家賃免除を維持するために追加のラポートが必要かどうかを定期的に確認できます。
* **コスト見積もり:** さまざまなサイズのプログラムを展開したり、データアカウントを作成したりする際のSOLコストを見積もります。
* **ウォレットとSDKの統合:** ウォレットとSDKはこれを使用して、新しいアカウントに適切に資金を提供できるようにします。

## リクエストパラメータ

1. **`dataLength`** (`usize`, 必須): アカウントのデータの長さ（バイト単位）。これは家賃免除の最小値を決定する主な要因です。
   * 例: `165`（標準SPLトークンアカウントの場合）。

2. **`commitment`** (`object`, 任意): クエリの[コミットメントレベル](https://www.helius.dev/blog/solana-commitment-levels)を指定します。省略した場合、RPCノードのデフォルトコミットメントが使用されます。
   * フィールド:
     * `commitment` (string): 例：`"finalized"`, `"confirmed"`, または`"processed"`。

## レスポンス構造

JSON-RPCレスポンスの`result`フィールドは、指定された`dataLength`を持つアカウントが家賃免除を受けるために必要なラポートの最低数を表す`u64`（符号なし64ビット整数）になります。

## 例

### 1. 標準トークンアカウント（165バイト）の家賃免除の取得

この例では、通常のSPLトークンアカウント（データサイズ165バイト）が家賃免除を受けるために必要な最低残高を照会します。

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

  ```javascript JavaScript (using @solana/web3.js) theme={"system"}
  // Replace <api-key> with your Helius API key
  const { Connection } = require('@solana/web3.js');

  async function fetchMinimumBalanceForRentExemption() {
    const connection = new Connection('https://mainnet.helius-rpc.com/?api-key=<api-key>');
    const dataLength = 165; // Data length for a typical SPL token account

    try {
      const lamports = await connection.getMinimumBalanceForRentExemption(dataLength);
      console.log(`Minimum lamports for rent exemption (data length ${dataLength} bytes): ${lamports} SOL: (${lamports / 1_000_000_000})`);
    } catch (error) {
      console.error(`Error fetching minimum balance for rent exemption for data length ${dataLength}:`, error);
    }
  }

  fetchMinimumBalanceForRentExemption();
  ```
</CodeGroup>

### 2. ゼロバイトアカウントの家賃免除の取得

これは、データがないアカウントの基本的な家賃免除を示しており、通常、どのアカウントにとっても絶対的な最小値です。

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

  ```javascript JavaScript (using @solana/web3.js) theme={"system"}
  // Replace <api-key> with your Helius API key
  const { Connection } = require('@solana/web3.js');

  async function fetchMinimumBalanceForZeroByteAccount() {
    const connection = new Connection('https://mainnet.helius-rpc.com/?api-key=<api-key>');
    const dataLength = 0;

    try {
      const lamports = await connection.getMinimumBalanceForRentExemption(dataLength);
      console.log(`Minimum lamports for rent exemption (data length ${dataLength} bytes): ${lamports} SOL: (${lamports / 1_000_000_000})`);
    } catch (error) {
      console.error(`Error fetching minimum balance for rent exemption for data length ${dataLength}:`, error);
    }
  }

  fetchMinimumBalanceForZeroByteAccount();
  ```
</CodeGroup>

## 開発者向けヒント

* **データサイズごとに変化する家賃:** アカウントのデータが大きくなるほど、家賃免除の最低額は高くなります。
* **ネットワークパラメータ:** レントの基礎コスト（バイト年あたりのラポート）は、理論的にはクラスタの投票によって変更できるネットワークパラメータですが、これはまれです。`getMinimumBalanceForRentExemption`メソッドは常にクラスタの状態に基づいて現在の値を返します。
* **ラポートとSOL:** レスポンスはラポートで提供されます。1 SOL = 1,000,000,000 ラポートであることを忘れないでください。
* **長期的な持続性に不可欠:** アカウントが家賃免除されることを確認することは、Solanaブロックチェーン上でデータの長期的な持続性を確保するために重要です。

このガイドは、Solanaアプリケーションでアカウントレンタルを効果的に管理するために`getMinimumBalanceForRentExemption` RPCメソッドを理解し使用するのに役立ちます。
