Day 16 of RareSkills Solana Course.
- Configure Solana to run on localhost:
solana config set --url localhost
- Run the test validator node on another terminal:
solana-test-validator
- Run Solana logs on another terminal:
solana logs
- Build Anchor program:
anchor build
- Sync program_id with Anchor key:
anchor keys sync
- Run tests:
anchor test --skip-local-validator
- A
Solana program's bytecode
can be updated by the owner unless the program is marked asimmutable
.- Same behavior applies for
Solana storage
.
- Same behavior applies for
- Everything in Solana
is an account
(aprogram account
or astorage account
). - A
program account
hasexecutable
set totrue
. - A
storage account
hasexecutable
set tofalse
. - The
address
of the initialized accounts in Solana depends on:- the program that owns the storage account
- and the
seeds
- Accounts cannot be initialized twice.
- Solana storage are massive key-value stores.
- key is a
base 58 encoded address
. - value is a data blob that can be up to
10 MB
in size.
- key is a
Any program
canread
storage variables, but only theowner program
canwrite
to it's own storage variables.- A
Solana storage account
needs to be initialized (created) first before writing data to it.- It's possible to
initialize
andwrite data
in one transaction, but this introduces security issues.
- It's possible to
- Solana programs in Anchor treat all storage (or account data) as a
struct
.- Anchor
deserializes
andserializes
account data intostructs
behind the scenes, whenreading
orwriting
data. #[account]
macro implements theserialization
/deserialization
ofstructs
toblob
, and vice versa.
- Anchor
- You're not required to use
structs
for Solana storage, butstructs
are a current convention. - The
signer
pays for thestorage cost
(gas).