Hello again! Welcome back to our module on Solana Blockchain Fundamentals.
In the last lesson, we established the most critical concept in Solana's architecture: the strict separation of code and data. You learned that programs are stateless logic stored in executable accounts, and all state is kept in separate non-executable data accounts.
This leads to a practical question: storing data isn't free. The thousands of validator nodes that make up the Solana network must store all this account data in their memory or on fast SSDs. Who pays for this persistent storage? Today, we will answer that question. Your learning outcome is to explain the concept of rent and its role in the Solana economic model.
What is Rent?
On Solana, "rent" is the cost associated with keeping an account's data stored on the blockchain. Because validator hardware has real-world costs, the network charges for the resources used. Think of it like paying for storage on a cloud service like AWS S3 or a web hosting server. The more data you store, the more it costs.
This mechanism serves two main purposes:
- To compensate validators for the cost of storing account data.
- To prevent state bloat by encouraging developers and users to only store necessary data and to clean up unused accounts, preventing the blockchain from becoming cluttered with abandoned data.
Let's begin with a clear, concise article that defines rent and its purpose.
What is Rent on Solana and How to Calculate it
This guide from QuickNode provides an excellent overview of rent. It explains what it is, why it exists, and introduces the key idea that rent is refundable.
Please read the 'Overview' section. Pay close attention to the two reasons the Solana protocol charges rent.
The Modern Approach: Rent Exemption
As you just read, accounts with a balance below a certain threshold could be removed. Historically, rent was a small fee collected periodically (every epoch, which is roughly 2-3 days). However, this model was complex.
Today, the standard practice has shifted. Instead of paying recurring fees, an account is required to hold a minimum balance that makes it rent-exempt.
An account is considered "rent-exempt" if its SOL balance is equal to or greater than the cost of two years' worth of rent for the amount of data it stores. This is a one-time, refundable deposit, not a fee.
- Why two years? The rationale is based on the idea that hardware costs tend to decrease over time. The network assumes that a deposit covering two years of storage will be sufficient to cover the cost of storing that data in perpetuity.
- What happens to the deposit? The SOL for rent exemption is held in the account's
lamportsfield. It is locked there as long as the account exists. If the account is closed, the full deposit is refunded to the account owner.
This video provides a great explanation of this shift from periodic payments to the one-time rent-exempt deposit model.
A simple introduction to Solana accounts, rent, and PDAs
This video from Abdullah Raza clearly explains the evolution of rent and the concept of rent exemption. It clarifies why you now make a one-time deposit instead of paying recurring fees.
Watch the segment from 3:57 to 6:17. Focus on understanding why storing data costs SOL and what it means for an account to be 'rent-exempt'.
Calculating the Rent-Exempt Deposit
The amount of SOL required for rent exemption is directly proportional to the size of the data being stored in the account. A larger account needs a larger deposit.
Fortunately, you don't have to guess this value. Solana provides tools to calculate it precisely. Given your background in web development and your goal to build dApps, you'll find the programmatic methods especially useful.
The following guide demonstrates the three primary ways to determine the rent-exempt minimum for an account.
What is Rent on Solana and How to Calculate it
This is the practical part. Let's see how to calculate the rent deposit. This section of the QuickNode guide shows how to do it using the Solana CLI, the @solana/web3.js library, and the Anchor framework.
Read the section 'How to Calculate Rent-Exempt Threshold' and its three sub-sections. The Web3.js example using getMinimumBalanceForRentExemption is very similar to what you'll use in dApp frontends. The Anchor space constraint is what you'll use when writing programs.
As you saw, the methods are straightforward:
- Solana CLI:
solana rent <SIZE_IN_BYTES>is great for quick checks during development. - @solana/web3.js: The
connection.getMinimumBalanceForRentExemption(dataSize)function is what you'll use in your frontend JavaScript/TypeScript code to determine how much SOL is needed to create a new account. - Anchor: The
#[account(space = ...)]macro simplifies this even further on the program side. When you initialize an account with a specificspace, Anchor automatically handles the transfer of the required rent-exempt deposit from the payer.
Reclaiming Your Rent: Closing an Account
Since the rent-exempt balance is a deposit, not a fee, you can get it back. To do so, you must close the account.
Closing an account does two things:
- It purges all of the account's data from the blockchain.
- It transfers the entire remaining SOL balance (including the rent deposit) from the closed account to a designated recipient wallet.
This creates a powerful economic incentive for developers to build functions that allow users to close accounts they no longer need, promoting good "blockchain hygiene." It's also a common feature you'll see in Solana wallets and dApps.
This next video provides a very practical demonstration of how users can reclaim rent from unused accounts.
How to Close Solana Token Accounts and Reclaim Your SOL Rent?
Seeing this in action from a user's perspective is very helpful. This video from Seb Montgomery shows how to close accounts and reclaim SOL using a wallet and other popular ecosystem tools.
Watch the segments from 0:00-0:41, 0:34-1:21, 1:14-2:30, and 4:08-5:37. Notice the garage analogy, how accounts with zero balance can be closed, and the key takeaway that you can always re-create an account later by paying the rent again.
Test your understanding!
You are designing a social media dApp on Solana where users can have profiles. A user profile account needs to store a username (32 bytes), a bio (128 bytes), and a link to a profile picture (64 bytes).
- What is the main on-chain cost incurred when a new user signs up?
- What feature should you implement for users who decide to delete their profile, and what is the benefit to the user?
Show answer
- The main on-chain cost is the one-time, refundable rent-exempt deposit required to create the new profile account. The size of the account's data would be at least
32 + 128 + 64 = 224bytes, plus an 8-byte discriminator if using Anchor, for a total of232bytes. The program would calculate the SOL deposit needed for an account of this size. - You should implement a function that allows users to close their profile account. The benefit to the user is that closing the account will refund the entire rent-exempt SOL deposit back to their wallet.
Conclusion
You've now learned about the second pillar of Solana's on-chain economy. Where the account model defines how data is stored, rent defines the cost of that storage.
Here are the key takeaways from this lesson:
- Rent is the cost of storage: It exists to compensate validators and prevent the blockchain from being filled with unused data.
- Rent-exemption is the standard: Instead of paying recurring fees, accounts are funded with a one-time, refundable SOL deposit to make them rent-exempt.
- Deposit size is proportional to data size: The more data an account holds, the larger the required rent-exempt deposit. This can be calculated using the Solana CLI, Web3.js, or handled automatically by Anchor.
- Rent is refundable: By closing an account, its data is erased from the chain, and its entire SOL balance, including the rent deposit, is returned to the owner.
In our last lesson, we covered what accounts are. Today, we've covered the cost of those accounts. In our next lesson, we will learn about the structure of a Solana transaction, which is the mechanism we use to actually interact with and modify these accounts.
Can't find a good explanation? Sign up and we'll make it for you
Sign up