solana-development
solana-development
## Solana Playground
[Solana Playground](https://beta.solpg.io/) is browser-based application that will
let you write, build, and deploy onchain Solana programs. All from your browser. No
installation needed.
> Your Playground Wallet will be saved in your browser's local storage. Clearing
your browser cache will remove your saved wallet. When creating a new wallet, you
will have the option to save a local copy of your wallet's keypair file.
## Local development
1. [Solana CLI](https://docs.solanalabs.com/cli/install)
- `solana --version`
- to install new updates `agave-install update`
3. Nodejs (typescript). Installed using [fnm](https://github.com/Schniz/fnm)
- `fnm ls-remote`
- `fnm install v22`
- `fnm use v22`
- `node --version`
- `npm install --global yarn`
- `yarn --version`
5. [Rust](https://www.rust-lang.org/tools/install)
- `rustc --version`
- `rustup update`
6. an IDE, probably visual studio code using `brew`
7. [Anchor](https://www.anchor-lang.com/docs/installation), Solana Smart Contract
framework
- Using the Anchor version manager AVM
- `cargo install --git https://github.com/coral-xyz/anchor avm --force`
- `avm --version`
- Install the latest version of Anchor CLI using AVM:
- `avm install latest`
- `avm use latest`
- `anchor --version`
## Solana CLI
get info about current connected cluster: devnet, mainnet, etc.
```sh
solana config get
solana config set --url mainnet-beta
solana config set --url devnet
solana config set --url localhost
solana config set --url testnet
```
- connected cluster: a set of network nodes that work together to maintain a
synchronized copy of the blockchain. These clusters are essential for providing a
decentralized, distributed ledger and powering the Solana network by validating
transactions, securing the chain, and executing programs (smart contracts).
The `RPC URL` and `Websocket URL` specify the Solana cluster the CLI will make
requests to.
The `Keypair Path` specifies the location of the default wallet used by the Solana
CLI (to pay transaction fees and deploy programs).
## Intro to Development
Development on Solana can be broken down into two main parts:
- Onchain Program Development: This is where you create and deploy custom programs
directly to the blockchain. You can write these programs in Rust, C, or C++
- Client Development: This is where you write software (called decentralized
applications, or dApps) that communicates with onchain programs. Client development
can be written in any programming language.
The "glue" between the client side and the onchain side is the [Solana JSON RPC
API](https://solana.com/docs/rpc). The client-side sends RPC requests to the Solana
network to interact with onchain programs. This means that anyone can interact with
your onchain program without the need of issuing API keys or any other form of
permission.

you'll be working with a blockchain and have to think about how users potentially
interact with your application onchain instead of just on the frontend.
Just run one simple command to generate a new project! The scaffold will include
both an example frontend and an onchain program template
```sh
npx create-solana-dapp <project-name>
```
You can read more about create-solana-dapp [here](https://github.com/solana-
developers/create-solana-dapp)
There are a few different ways to test your program based on your language
preference:
-
[solana-program-test](https://docs.rs/solana-program-test/latest/solana_program_tes
t/) - Testing framework built in Rust
- [solana-bankrun](https://kevinheavey.github.io/solana-bankrun/) - Testing
framework built for writing Typescript tests
## Core Concepts
Accounts on Solana:
- can store "state" or "executable" programs.
- State: This is data that's meant to be read from and persisted.
- Executable Programs: These are accounts that contain the actual code of Solana
`programs`.
- Accounts can store up to 10MB of data and the data stored on every account on
Solana has the following structure known as the AccountInfo.
- Data: Bytes (state of the account: data or executable code)
- Executable: Boolean
- Lamports: Number
- Owner: Program Address
- Accounts require a rent deposit in SOL, proportional to the amount of data
stored, which is fully refundable when the account is closed.
- Each one has an `address` (epresented as 32 bytes in the format of an [Ed25519]
(https://ed25519.cr.yp.to/) PublicKey) that serves as its unique ID used to locate
its corresponding on-chain data.
- All `wallet` accouns are ownwed by the `System Program` with the address
`11111111111111111111111111111111`
- All executable accounts are owned by the `Upgradable BPF Loader` with the address
`BPFLoaderUpgradeab1e11111111111111111111111`
- Only the program designated as the owner of an `account` can modify the data
stored on the `account` or deduct the lamport balance.
- Sysvar accounts are special accounts that store network cluster state. Full list
[here](https://docs.anza.xyz/runtime/sysvars)
#### Transaction
A Solana transaction consists of:
- Signatures: An array of signatures included on the transaction.
- Message: List of instructions to be processed atomically.
#### Instruction
An instruction is a request to process a specific action on-chain and is the
smallest contiguous unit of execution logic in a program. Each instruction in the
array specifies the following information:
- Program ID: Identifies an on-chain program that will process the
instruction.
- Compact array of account address indexes: Accouns required by the
instruction
- Compact array of opaque u8 data: This data specifies the instruction to
invoke on the program along with any additional data that the instruction requires.
For every account required by an instruction, the following info must be specified:
- pubkey: The on-chain address of an account
- is_signer: Specify if the account is required as a signer on the transaction
- is_writable: Specify if the account data will be modified