Solana Initial Explorations

Accounts and Key Pairs

System Program

It’s the native program which allows to perform several account related tasks such as (from Solana docs):

  • New Account Creation: Only the System Program can create new accounts.
  • Space Allocation: Sets the byte capacity for the data field of each account.
  • Assign Program Ownership: Once the System Program creates an account, it can reassign the designated program owner to a different program account. This is how custom programs take ownership of new accounts created by the System Program.

Account Types in Solana

  • Executable Accounts: Store immutable bytecode and cannot be changed.
  • Non-Executable Accounts: Store data and it can be changed.

A Wallet in Solana

An account owned by the Sytem Program. The lamport balance of the wallet is the amount of SOL owned by the account.

Only accounts owned by the System Program can be used as transaction fee payers.

Local Explorations

There’s no better way to learn than to put the concepts in practice. So here we are. Below it is the setup I used to start exploring account related topics in Solana.

I setup a local testnet following these instructions and from there, I generate an account, seed it and performed a transaction.

// starts local network on port http://localhost:8899
solana-test-validator

// returns the SRP and the pubkey in base58 format
solana-keygen new

// seeds your account with 10 SOL
solana airdrop 10 <PUB_KEY> --url http://localhost:8899

Generating Key-Pairs

 solana-keygen grind --starts-with so:10

The SRP can 12 mnemonic words:

Pirvate Key from a given account are often represented as an array of 64 bytes, where the first 32 bytes are the actual private key and the remaining 32 bytes are the public key.

[133,22,251,51,252,24,78,35,211,31,144,59,118,252,142,71,215,178,95,101,160,88,14,154,86,161,162,32,83,169,131,232,162,153,217,83,159,182,19,197,188,75,115,81,36,88,190,246,4,76,194,138,33,185,213,81,29,59,43,254,196,144,144,76]

Sending a Transaction

Whenever you send a token to another address you the other wallet needs to have a token account to save these tokens. These token accounts costs some sol in rent to be saved on the blockchain.

Someone needs to pay for this. So if you add the flag

--allow-unfunded-recipient

to your transfer you pay for the token account on the other side. So just add it to the end of your command

solana transfer --from "KEY_PAIR.json" RECIPIENT_ADDRESS 1 --allow-unfunded-recipient

Interacting with the RPC

getAccountInfo

Anchor

Project Setup and Run first Test

// Local Network
  // Setup local network
  solana config set --url localhost
  solana-test-validator

  // Reset local network
  solana-test-validator --reset

// Inside the Anchor project
  // Start a project
  anchor init PROJECT_NAME
  cd PROJECT_NAME
  anchor build

  // Sync program id
anchor keys sync

  // Run the tests
anchor test --skip-local-validator

// Debugging
anchor logs

Arithmetic and Basic Types