Open this lesson in your favourite AI. It'll walk you through the why, explain the demo, and quiz you on the try-it list.
Solana charges rent for every account: a per-byte-per-epoch fee paid in lamports. You almost never pay rent in practice because virtually every account is rent-exempt — they hold enough SOL (≈2 years of rent) to exempt them forever. But this rent model explains why account creation costs SOL, why closing accounts refunds SOL, and why you cannot have zero-balance accounts linger. Getting this straight prevents the most common devnet error: 'insufficient lamports to make account rent-exempt.'
A Counter account stores 16 bytes (8 discriminator + 8 u64). Rent-exempt minimum for 16 bytes is ~0.00089 SOL. When you initialize the account with Anchor's init constraint, the payer transfers that ≈0.00089 SOL to the account; it becomes rent-exempt forever. Close the account later and you get it back. The space = 8 + 8 line in your Anchor Accounts struct is what determines the rent-exempt cost.
# Account rent calculation — shell commands to see it live.
# 1) Minimum rent-exempt balance for an account of size N bytes
solana rent 16
# Output: Rent-exempt minimum: 0.00089088 SOL
solana rent 1000
# Output: Rent-exempt minimum: 0.00789264 SOL
solana rent 10000000 # 10 MB — typical state-compression tree root
# Output: Rent-exempt minimum: 69.567 SOL
# 2) An account's current balance vs rent-exempt minimum
solana account <SOME_PUBKEY>
# Balance: 0.00089088 SOL (rent-exempt)
# 3) Closing a Counter account refunds the rent
# In Anchor: #[account(mut, close = payer)] pub counter: Account<..>
# Transaction drains the lamports back to payer.solana rent <N> on your machine.close = payer and observe the payer's SOL balance increase by exactly the rent-exempt deposit. Confirm on the explorer that the account is now gone.Use these three in order. Each builds on the one before.
In one paragraph, explain Solana rent and rent-exemption — why accounts cost SOL, what 'exemption' means, and where the SOL goes when an account is closed.
Walk me through the rent mechanism step by step: how is rent calculated per byte, when does the runtime check it, and what prevents accounts from being collected for non-payment today?
Given I'm designing a protocol where each user creates 5 PDA accounts (each 200 bytes), how much SOL does onboarding a new user cost in rent-exempt minimums, and what are three UX strategies to amortise or avoid that cost (subsidy, account compression, account reuse)?