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.
To calculate the minimum rent balance without making an RPC call:
TypeScript
import { getMinimumBalanceForRentExemption } from "gill";// allocate 1.5k bytes of extra space in the account for dataconst space = 1500n;const lamports = getMinimumBalanceForRentExemption(space);console.log("Minimum balance for rent exemption:", lamports);
Or you can request the minimum rent balance via RPC call (should the rent calculation values become dynamic in the future):
TypeScript
import { createSolanaClient } from "gill";const { rpc } = createSolanaClient({urlOrMoniker: "devnet", // or `mainnet`, `localnet`, etc});// allocate 1.5k bytes of extra space in the account for dataconst space = 1500n;const lamports = await rpc.getMinimumBalanceForRentExemption(space).send();console.log("Minimum balance for rent exemption:", lamports);
Is this page helpful?