How to Calculate Account Creation Cost
Keeping accounts alive on Solana incurs a 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.
calculate-rent.ts
import { createSolanaRpc } from "@solana/web3.js";
const rpc = createSolanaRpc("https://api.devnet.solana.com");
// 1.5k bytes
const space = 1500n;
const lamports = await rpc.getMinimumBalanceForRentExemption(space).send();
console.log("Minimum balance for rent exception:", lamports);