Solana CookbookAccounts
How to Calculate Account Creation Cost
Keeping accounts alive on Solana incurs a data storage cost called rent. For the calculation, you need to consider the amount of data you intend to store in the account. Rent can be reclaimed in full if the account is closed.
import { getMinimumBalanceForRentExemption, createSolanaClient } from "gill";// allocate 1.5k bytes of extra space in the account for dataconst space = 1500n;// To calculate the minimum rent balance without making an RPC call:const lamports = getMinimumBalanceForRentExemption(space);console.log("Minimum balance for rent exemption:", lamports);const { rpc } = createSolanaClient({urlOrMoniker: "http://127.0.0.1:8899" // or `mainnet`, `localnet`, etc});const lamportsFromRpcCall = await rpc.getMinimumBalanceForRentExemption(space).send();console.log("Minimum balance for rent exemption:", lamports);
Is this page helpful?