getMinimumBalanceForRentExemption
Returns the minimum balance required to make an account rent exempt for a given data size. On Solana, accounts must maintain a minimum SOL balance proportional to their data size to avoid being purged by the runtime. This method is essential when creating new accounts, as you need to know exactly how much SOL to fund them with to ensure they persist indefinitely.
Parameters
| # | Type | Required | Description |
|---|---|---|---|
| 1 | usize | Yes | Account data length in bytes |
| 2 | object | No | Configuration object |
Configuration object fields:
| Field | Type | Description |
|---|---|---|
commitment | string | Commitment level: processed, confirmed, or finalized |
Response
Returns a single value:
| Field | Type | Description |
|---|---|---|
result | u64 | Minimum lamports required for rent exemption |
Code Examples
cURL
1curl http://[IP_ADDRESS]:[PORT] -X POST -H "Content-Type: application/json" -d '{
2 "jsonrpc": "2.0",
3 "id": 1,
4 "method": "getMinimumBalanceForRentExemption",
5 "params": [
6 165
7 ]
8}'TypeScript
1const response = await fetch("http://[IP_ADDRESS]:[PORT]", {
2 method: "POST",
3 headers: { "Content-Type": "application/json" },
4 body: JSON.stringify({
5 jsonrpc: "2.0",
6 id: 1,
7 method: "getMinimumBalanceForRentExemption",
8 params: [
9 165
10 ]
11 }),
12});
13const { result } = await response.json();
14console.log("Rent-exempt minimum:", result / 1e9, "SOL");Python
1import requests
2
3response = requests.post("http://[IP_ADDRESS]:[PORT]", json={
4 "jsonrpc": "2.0",
5 "id": 1,
6 "method": "getMinimumBalanceForRentExemption",
7 "params": [
8 165
9 ]
10})
11result = response.json()["result"]
12print(f"Rent-exempt minimum: {result / 1e9} SOL")Rust
1use reqwest::Client;
2use serde_json::json;
3
4#[tokio::main]
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let client = Client::new();
7 let res = client.post("http://[IP_ADDRESS]:[PORT]")
8 .json(&json!({
9 "jsonrpc": "2.0",
10 "id": 1,
11 "method": "getMinimumBalanceForRentExemption",
12 "params": [
13 165_usize
14 ]
15 }))
16 .send().await?
17 .text().await?;
18 println!("{}", res);
19 Ok(())
20}Example Response
1{
2 "jsonrpc": "2.0",
3 "result": 2039280,
4 "id": 1
5}