DEV Community

Hope
Hope

Posted on

Solana Accounts Explained to a Web2 Developer

If you are coming from a traditional Web2 background (like building with Node.js, databases, or cloud servers), your first look at a blockchain can be confusing. You hear terms like smart contracts and state transition, but how does data get saved?

On Solana, Everything is a file.

Well, Solana calls them Accounts, but they act just like files in a computer operating system. Let's break down how Solana stores data using terms you already know.

1. The Big Idea: Everything is a File (Account)

In Web2, you might use a Linux server. On that server, you have executable files (programs) and data files (such as .json or .txt).

Solana works the same way. Instead of a hard drive, Solana uses a giant, flat key-value store.

  • The Key: A 32-byte string called a Public Key (like So11111111111111111111111111111111111111112). This is your file name or path.
  • The Value: The account itself. This is the actual file contents and metadata.

Whether it's a user wallet, a piece of code, a token balance, or a picture of an NFTβ€”on Solana, it is always an account.

2. The 5 Fields Inside Every Account

Just like a file on your computer has a size, an owner, and permissions, every single Solana account contains the same five pieces of information:

Field What it means in Web2 terms
Lamports The bank balance of the file. A lamport is a tiny fraction of a SOL coin (1 SOL = 1 billion lamports).
Data The actual contents of the file. A flat array of bytes where you can save any information.
Owner The specific program (app) that is allowed to change this file's data.
Executable A true/false switch. If true, this file is a program (code). If false, it's just data.
Rent Epoch A background field used by the network (mostly system maintenance data).

Here is what it looks like if you inspect a real account using the Solana command line:

{
  "lamports": 2039280,
  "data": ["SGVsbG8gV29ybGQ=", "base64"],
  "owner": "11111111111111111111111111111111",
  "executable": false,
  "rent_epoch": 18446744073709551615
}

Enter fullscreen mode Exit fullscreen mode

3. Programs are Stateless

This is the biggest surprise for Web2 developers.

In Web2, your app server usually holds some data in memory, or your code handles its own database connections. On Solana, programs (smart contracts) cannot store data inside themselves. They are stateless.

Think of it like this:

  • The Program Account: This is your compiled code. Its executable flag is set to true. It sits there like a web server application, ready to run.
  • The Data Account: This is your database row. Its executable flag is false.

When a user wants to interact with an app, they pass both the Program (the code) and the Data Account (the file) to the network. The program reads the data file, updates it, and saves it back.

4. The Golden Rule: App Security

How do we stop people from changing your data account and giving themselves a million tokens? Solana has a very strict security rule built into its core:

Only the program listed as the "Owner" of an account can change its data.

If Program A tries to modify a data file owned by Program B, the Solana network rejects the change. However, anyone is allowed to send money (lamports) into any account. You can deposit money into a friend's bank account, but only the bank's system can update their account status.


5. Rent: Paying for Storage Space

On a cloud platform like AWS, you pay a monthly fee to keep your files stored on a hard drive. If you stop paying, AWS deletes your files.

Solana manages storage similarly, but with a twist. To keep a file on the blockchain, the account must hold a minimum amount of SOL coins. The bigger your data file, the more SOL you need to leave in it. This is called being Rent-Exempt.

For a basic wallet account with no extra data, it costs a tiny fraction of a cent (around 0.00089 SOL) to stay on the network forever. If you ever close the account and delete the file, you get all that SOL back!

Wrapping Up

To survive and build on Solana, just remember these four rules:

  1. Everything is a file called an account.
  2. Code and data live in completely separate files.
  3. Programs are stateless; they just read and write to data accounts.
  4. Only the owner program can modify a file's data.

Once you view the blockchain as a giant, secure file system, writing applications becomes much easier to visualize!

Top comments (0)