Accounts

Everything (almost) is an account on Solana blockchain. Even smart contracts, which are called programs on Solana blockchain are accounts. Sounds weird, right? But don’t worry I will explain it. Let’s start with a description of a structure of an account. The following diagram describes the structure of Solana account.

You may ask wtf is Solana Account information or User space?

You can imagine Solana account information as a namespace for AccountMetada. This metadata contains all necessary information for Solana runtime to operate this account.

The key of the account is used to uniquly represent this account.

The key may be either:

  • an ed25519 public key,
  • a program-derived account address (32byte value forced off the ed25519 curve),
  • a hash of an ed25519 public key with a 32 character string.

is_signer and is_writable determine a role of this account in transactions. We will explain transaction later, so don’t worry too much. It will make more sense later.

The most confusing field can be owner, mainly because even your account is not owned by you. All accounts in Solana are owned by programs. Some accounts are owned by System program, and some can be owned by your smart contract (which is just a program, remember?). So at the end the owner field is just PubKey or you can say Program ID of another program. Only the owner can modify user space data and has permission to withdraw lamports. Everyone else can only read the data or credit lamports to an account.

 

So to better understand that you are not owner of your account let describe image above. Bob’s account is owned by the System Program, but key field is set to his PubKey. You may wonder if the SystemProgram can debit Bob’s account without his permission, and the answer is not because SystemProgram check whenever Bob’s private key signed transactions to debit his account.

That means that only Bob has write access to this account.

Executable field is pretty straightforward. It’s just a boolen which represents if this account is executable which means that Data of this account is a byte code. Such accounts are called programs on Solana, and you can make RPC calls to them. Also it’s important to mention that once the account is marked as executable, you can’t take it back.

When the account is marked as executable it becomes a program so it can own another accounts, which means that there can be some account and his Owner field can be set to Program ID of this program (account).

Rent epoch field just says when is the next time you should pay rent for your account. But in the most cases you pay enough Lamports so your account becomes rent exempt and this field will be set to 0. If you want to know more about rent check Solana docs.

Lamports represent how much Lamports an account has.

Data holds an array of bytes which can represent an arbitrary data structure,so it can be used as a state for storing arbitrary information. If an account is marked as executable than this field contains a loaded program.