Lamports, rent, and account lifecycle
Suggest an editEvery account on Solana costs something to keep on the chain. The cost works the way a security deposit at an apartment works: you pay it up front, the chain holds it while the account exists, and you get it back when the account closes.
One SOL is divided into one billion smaller units called lamports, and everything on the chain is measured in lamports: balances, fees, storage deposits, validator rewards. The base fee for one transaction signature is five thousand lamports, or 0.000005 SOL, and the storage deposit for a typical token account is around two million lamports, or 0.00204 SOL.
Rent is a deposit that stays locked while the bytes are in use
Every byte of data on the chain has to be held in memory by every validator on the network. Holding data has a cost, and the chain charges for it. The name for that charge is rent.
On Ethereum storage is paid for at the moment of the write. The writer pays gas once, and the value then has to be held by every full node until something overwrites it. Clearing the value later returns only part of that gas. Solana ties the payment to the lifetime of the data. Each account holds a deposit in lamports that stays locked for as long as the bytes are occupied and comes back in full when the account is closed, so whoever receives the refund has a reason to close an account that is no longer used.
Solana originally also let an account pay a small amount each epoch out of its lamports balance until it ran out and got deleted. That mode was deprecated, and only the deposit remains. Every account on Solana today is rent-exempt, meaning it holds a minimum lamport balance proportional to its size that stays locked for as long as the account exists. When a developer says "rent" they mean this one-time deposit rather than an ongoing fee.
The deposit covers roughly two years of that per-epoch rent, which comes to about 6,960 lamports per byte, counted over the account's data plus 128 bytes of overhead. An empty wallet costs about 890,000 lamports. A 165-byte token account costs about 2,040,000 lamports. A 200-kilobyte program account costs about 1.4 SOL.
An account is created, held for free, and closed for a refund
Creating an account takes one instruction from the System Program. That instruction does three things in one step: it allocates the right number of bytes for the account's data, transfers the rent-exempt deposit from a payer into the account's lamports field, and assigns ownership to a target program.
Holding an account does not cost anything. As long as the rent-exempt deposit is in place, the account stays on the chain indefinitely, with no further fee and no expiration.
Closing an account is two operations packed into one. The owner program zeros out the data field and transfers the entire lamports balance out to a recipient address you specify. Once the balance hits zero, the runtime considers the account uninitialized, and an account can be created at the same address again.
Size accounts, choose who pays, and close them when done
Size. Every account is sized at creation, and when you decide how big an account should be, you decide its cost. By the formula above, a 10,000-byte account costs about thirty times more than a 200-byte one. There is no penalty for using small accounts, so most production programs keep their accounts as small as the data they need to store. An account also cannot grow without bound. Its data is capped at ten megabytes, and growing it later takes a deliberate call that pays additional deposit for the new bytes.
Who pays. The deposit comes from one of the accounts listed in the transaction, marked as the payer. Your program does not pay out of its own balance. Choosing the payer is a design decision. The team can pre-create an account for every user and pay for all of them, or the program can create the account on a user's first action, funded by that user. Almost always it is the user whose action triggered the creation, since the user is the one who benefits from the new account existing. Tokens raise the same question. A wallet needs a separate token account for each token it holds, so the first time a wallet receives a given token, either the sender or the recipient has to lock about 2,040,000 lamports for the new account.
Close. When you want to clean up after a user, you close the account and send its lamports back to them, so their net storage cost is zero. The Anchor framework you'll be using has a close constraint that does this in one line. Programs that skip cleanup leave unused accounts on the chain and force their users to pay for storage they no longer need. A closed account can be brought back. Anyone can send lamports to its address later in the same transaction, and the runtime then keeps the account alive. Account closure and realloc shows the attack this allowed and how the close constraint prevents it.
For every account your program creates, decide who pays the deposit and who receives it when the account closes.