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: what is Solana Account information or User space You can think of Solana account information as a namespace for AccountMetadata. 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 transactions later, so don’t worry too much about them yet.
The most confusing field can be owner, mainly because even your account is not owned by you. All accounts on Solana are owned by programs. Some accounts are owned by the System program, and some can be owned by your smart contract (which is just a program, remember?). In the end, the owner field is just a PubKey, or, you can say the 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.
To better understand that you are not owner of your account, let’s take a look at the image above. Bob’s account is owned by the System Program, but the 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 checks whenever Bob’s private key signed transactions to debit his account. That means that only Bob has write access to this account.
The Executable field is pretty straightforward. It’s just a boolean 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 an account, and his Owner field can be set to Program ID of this program (account).
The Rent epoch field just says when you will pay rent for your account next. However, in 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 out the Solana docs.
Lamports represent how many Lamports an account has. (Balance)
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.
We hope this helps you better understand Solana programs!