# getMinimumBalanceForRentExemption

The `getMinimumBalanceForRentExemption` RPC method calculates the minimum number of lamports required for an account of a given data size to become rent-exempt on the Solana network. Rent exemption ensures that accounts retain their balance indefinitely, avoiding depletion due to storage rent charges. An account becomes rent-exempt when its balance equals at least two years' worth of rent.

***

**🧩 Common Use Cases**

* **Account Initialization**: When creating accounts (e.g., SPL Token accounts, PDAs, or custom data structures), use this method to allocate the appropriate lamport amount for rent exemption.
* **Dynamic Sizing**: For applications where account size changes over time, recalculate the minimum balance to maintain rent exemption as the data grows.
* **Deployment Cost Estimation**: Estimate SOL requirements for deploying programs or initializing accounts with various data sizes.
* **Wallet & SDK Integration**: Wallets and Solana SDKs often use this method to ensure rent-exempt balances when creating accounts.

***

**🔧 Request Parameters**

```json
{
  "dataLength": <usize>,      // Required. Size of the account data in bytes.
  "commitment": {             // Optional.
    "commitment": "finalized" // e.g., "processed", "confirmed", or "finalized"
  }
}
```

* **dataLength**: Number of bytes the account will store (e.g., 165 for a typical SPL Token account).
* **commitment**: Optional commitment level to define how finalized the queried state should be.

***

**📦 Response Structure**

```json
{
  "result": <u64>
}
```

* **result**: The minimum number of lamports required to make an account of the given `dataLength` rent-exempt.

***

**🧪 Examples**

1. **Standard SPL Token Account (165 bytes)**

   ```bash
   bashCopyEditgetMinimumBalanceForRentExemption(165)
   ```

   Returns the lamports needed to make a token account rent-exempt.
2. **Zero-Byte Account**

   ```bash
   bashCopyEditgetMinimumBalanceForRentExemption(0)
   ```

   Returns the smallest possible rent-exempt value—useful for bare minimum accounts.

***

**Code Examples**

{% tabs %}
{% tab title="Nodejs" %}

```javascript
const fetch = require('node-fetch');

async function getMinimumBalanceForRentExemption(rpcUrl) {
  try {
    const response = await fetch(rpcUrl, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        jsonrpc: '2.0',
        id: 1,
        method: 'getMinimumBalanceForRentExemption',
        "params": [
            0
          ]
      }),
    });

    const data = await response.json();
    
    // Print the exact full response
    console.log('Full RPC Response:');
    console.log(JSON.stringify(data, null, 2));
    
    return data;
  } catch (error) {
    console.error('Error getting health:', error.message);
    return null;
  }
}

// Example usage
const RPC_URL = 'https://rpc.coinvera.io/?x-api-key=your-coinvera-x-api-key';

getMinimumBalanceForRentExemption(RPC_URL);
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

def get_minimum_balance_for_rent_exemption(rpc_url):
    try:
        response = requests.post(
            rpc_url,
            headers={
                'Content-Type': 'application/json',
            },
            json={
                'jsonrpc': '2.0',
                'id': 1,
                'method': 'getMinimumBalanceForRentExemption',
                'params': [0]
            }
        )
        
        data = response.json()
        
        # Print the exact full response
        print('Full RPC Response:')
        print(json.dumps(data, indent=2))
        
        return data
        
    except Exception as error:
        print(f'Error getting health: {error}')
        return None

# Example usage
RPC_URL = 'https://rpc.coinvera.io/?x-api-key=your-coinvera-x-api-key'
get_minimum_balance_for_rent_exemption(RPC_URL)
```

{% endtab %}
{% endtabs %}

**Example Response**

```json
{
  "jsonrpc": "2.0",
  "result": 890880,
  "id": 1
}
```

***

**💡 Developer Tips**

* **Rent Scales With Size**: Larger accounts require more lamports to remain rent-exempt.
* **Dynamic Network Rate**: Rent is a network-level parameter (lamports per byte-year) and may change via cluster governance. This method always reflects the current rate.
* **Units**: Returned value is in lamports. (1 SOL = 1,000,000,000 lamports.)
* **Avoid Garbage Collection**: Rent-exempt accounts are protected from being removed due to insufficient balance, preserving important data over time.

***

This method is essential for developers who want to ensure their Solana accounts are sustainable and secure from unintended deletion due to rent mechanics.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.coinvera.io/integration/solana/rpc/getminimumbalanceforrentexemption.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
