Solana Core Concepts

Solana Core Concepts

Accounts

Accounts within Solana are used to store state. They are an essential building block for developing on Solana.

Facts

  1. Accounts are used to store data
  2. Each account has a unique address
  3. Accounts have a max size of 10MB (10 Mega Bytes)
  4. PDA accounts have a max size of 10KB (10 Kilo Bytes)
  5. PDA accounts can be used to sign on behalf of a program
  6. Accounts size are fixed at creation time, but can be adjusted using realloc
  7. Account data storage is paid with rent
  8. Default account owner is the System Program

Deep Dive

Account Model

There are 3 kinds of accounts on Solana:
  1. Data accounts store data
  2. Program accounts store executable programs
  3. Native accounts that indicate native programs on Solana such as System, Stake, and Vote
Within data accounts, there are 2 types:
  1. System owned accounts
  2. PDA (Program Derived Address) accounts

Each account has an address (usually a public key) and an owner (address of a program account).
The full field list an account stores is found below.

Fiels Description
lamports The number of lamports owned by this account
owner The program owner of this account
executable Whether this account can process instructions
data The raw data byte array stored by this account
rent_epoch The next epoch that this account will owe rent

A few important ownership rules:

  1. Only a data account’s owner can modify its data and debit lamports
  2. Anyone is allowed to credit lamports to a data account
  3. The owner of an account may assign a new owner if the account’s data is zeroed out

Program accounts do not store state.

For example, if you have a counter program that lets you increment a counter, you must create two accounts, one account to store the program’s code, and one to store the counter.
在这里插入图片描述

To prevent an account from being deleted, you must pay rent.

Rent

Storing data on accounts costs SOL to maintain, and it is funded by what is called rent. If you maintain a minimum balance equivalent to 2 years of rent payments in an account, your account will be exempt from paying rent. You can retrieve rent by closing the account and sending the lamports back to your wallet.

Rent is paid during two different timings:

  1. When referenced by a transaction
  2. Once an epoch
    A percentage of rent collected by accounts is destroyed, while the rest is distributed to vote accounts at the end of every slot.

If the account does not have enough to pay rent, the account will be deallocated and the data removed.

It is also important to note that new accounts must be rent exempt.

Programs

Any developer can write and deploy programs to the Solana blockchain. Programs (known as smart contracts on other protocols) serve as the foundation for on-chain activity, powering anything from DeFi and NFTs to Social Media and Gaming.

Facts

  1. Programs process instructions from both end users and other programs
  2. All programs are stateless: any data they interact with is stored in separate accounts that are passed in via instructions
  3. Programs themselves are stored in accounts marked as executable
  4. All programs are owned by the BPF Loader and executed by the Solana Runtime
  5. Developers most commonly write programs in Rust or
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

0010000100

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值