Quick Start
Solana Account Model

Solana Account Model

This section will guide you through understanding how data is represented on the Solana network, using Solana Playground (solpg) to fetch account data, and demonstrating with both CLI and web3.js examples.

  • how data is represented on solana network

  • add diagrams

  • use solpg to demonstrate/ fetch accounts

  • use tabs to separate cli / web3.js examples

Accounts

Solana accounts fall into two categories: program accounts and data accounts.

  • two categories, program / data accounts

  • Program Accounts, builtin / custom

  • Data Accounts

  • use solana playground and explorer as example

  • add diagrams to reforce idea

AccountInfo

  • data structure of every account
  • diagram + explain each field

Fetch AccountInfo

  • example using web3.js
  • swap address to fetch accountinfo for other accounts

https://beta.solpg.io/66608f8ecffcf4b13384d148

client.ts
import { PublicKey } from "@solana/web3.js";
 
const address = new PublicKey("11111111111111111111111111111111");
const accountInfo = await pg.connection.getAccountInfo(address);
 
console.log(JSON.stringify(accountInfo, null, 2));
Output
Running client...
  client.ts:
    {
  "data": {
    "type": "Buffer",
    "data": [
      115,
      121,
      115,
      116,
      101,
      109,
      95,
      112,
      114,
      111,
      103,
      114,
      97,
      109
    ]
  },
  "executable": true,
  "lamports": 1,
  "owner": "NativeLoader1111111111111111111111111111111",
  "rentEpoch": 18446744073709552000,
  "space": 14
}
  • fetch account info of playground wallet
client.ts
const address = pg.wallet.publicKey;
+ const address = pg.wallet.publicKey;
- const address = new PublicKey("11111111111111111111111111111111");
  • publickey does not mean there is an onchain account associated with address
  • generate new keypair, fetch address, return null
client.ts
import { Keypair } from "@solana/web3.js";
 
const address = new Keypair().publicKey;
const accountInfo = await pg.connection.getAccountInfo(address);
 
console.log(JSON.stringify(accountInfo, null, 2));
Output
Running client...
  client.ts:
    null

Data Accounts

  • separation of state and executable code
  • ’data accounts’, executable false, data field of accountinfo used to store state as byte array

Wallet Address

Solana Explorer Wallet Account

  • get address of playground wallet
Terminal
solana address
  • for example
Output
$ solana address
3z9vL1zjN6qyAFHhHQdWYRTFAcy69pJydkZmSFBKHg1R
  • use playground wallet address fetch account data
Terminal
solana account <ADDRESS>
Terminal
solana account 3z9vL1zjN6qyAFHhHQdWYRTFAcy69pJydkZmSFBKHg1R
Output
$ solana account 3z9vL1zjN6qyAFHhHQdWYRTFAcy69pJydkZmSFBKHg1R
 
Public Key: 3z9vL1zjN6qyAFHhHQdWYRTFAcy69pJydkZmSFBKHg1R
Balance: 32.67152584 SOL
Owner: 11111111111111111111111111111111
Executable: false
Rent Epoch: 18446744073709551615
  • add diagram mapping accountinfo to wallet app ui

  • wallets are accounts owned by system program

  • store 0 bytes of extra data

  • lamport on account = sol balance

Program Accounts

Native Program (Built In)

for example system program

  • notice that wallet is owned by system program, a built in program
  • fetch system program account
  • callout executable true
Terminal
solana account 11111111111111111111111111111111
Output
$ solana account 11111111111111111111111111111111
 
Public Key: 11111111111111111111111111111111
Balance: 0.000000001 SOL Owner:
NativeLoader1111111111111111111111111111111
Executable: true
Rent Epoch: 18446744073709551615

Solana Explorer System Program

Custom Program

for example token program

Solana Explorer Token Program

Terminal
solana account TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb
Output
$ solana account TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb
 
Public Key: TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb
Balance: 0.00114144 SOL
Owner: BPFLoaderUpgradeab1e11111111111111111111111
Executable: true
Rent Epoch: 18446744073709551615
  • cover in detail in programs section, only high-level concept here

Notes

  • intro to accounts
  • account info
  • generate keypair
  • show that on exploxer doesn’t exist by default
  • create account
  • show account on explorer
  • web3.js