getMinimumBalanceForRentExemption
Returns the lamports required to make an account of a given data size rent exempt.
Request
Send a JSON-RPC 2.0 POST request with method: "getMinimumBalanceForRentExemption". The params array takes the account data length in bytes and an optional configuration object.
curl · JSON-RPCjson
{ "jsonrpc": "2.0", "id": 1, "method": "getMinimumBalanceForRentExemption", "params": [ 50, { "commitment": "processed" } ]}@solana/kit
kit.tsts
import { createSolanaRpc } from "@solana/kit"; const rpc_url = "https://rpc.openinfra.sh";const rpc = createSolanaRpc(rpc_url); let dataLength = BigInt(50);let minBalForRentExemption = await rpc .getMinimumBalanceForRentExemption(dataLength) .send(); console.log(minBalForRentExemption);@solana/web3.js
web3.tsts
import { Connection } from "@solana/web3.js"; const connection = new Connection("https://rpc.openinfra.sh", "confirmed"); let dataLength = 50;let minBalForRentExemption = await connection.getMinimumBalanceForRentExemption(dataLength); console.log(minBalForRentExemption);Rust
main.rsrs
use anyhow::Result;use solana_client::nonblocking::rpc_client::RpcClient;use solana_commitment_config::CommitmentConfig; #[tokio::main]async fn main() -> Result<()> { let client = RpcClient::new_with_commitment( String::from("https://rpc.openinfra.sh"), CommitmentConfig::confirmed(), ); let data_len = 50; let min_bal_for_rent_exemption = client .get_minimum_balance_for_rent_exemption(data_len) .await?; println!("{:#?}", min_bal_for_rent_exemption); Ok(())}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| length | usize | Yes | The account's data length in bytes. |
| config | object | No | Optional configuration object. See fields below. |
| config.commitment | string | No | Desired finality level for the query. Accepted values: processed, confirmed, finalized (default). |
commitment values
| Value | Description |
|---|---|
| processed | Return data from the highest slot this node has processed on the fork it currently considers best. This is the newest view, but it can still change if the cluster switches forks. |
| confirmed | Return data from the highest slot that at least two-thirds of active stake has directly voted to confirm. More stable than processed, but a weaker guarantee than finalized. |
| finalized | Return data from the highest slot that the cluster recognizes as finalized. The slot has reached maximum vote lockout in validators' vote towers and is recognized by at least two-thirds of active stake. This is the strongest commitment level. |
Response
response.jsonjson
{ "jsonrpc": "2.0", "result": 1113600, "id": 1}The result is a u64 value representing the minimum lamport balance the account must hold to remain rent-free.
| Field | Type | Description |
|---|---|---|
| result | u64 | Minimum lamports required in the account to remain rent free. |