Skip to content

Latest commit

 

History

History
301 lines (167 loc) · 7.07 KB

02_dev_env.md

File metadata and controls

301 lines (167 loc) · 7.07 KB

🛹 Setup a Developing Environment


tl; dr


  • Local developing on Solana means you will set up a local validator so that programs can be tested before being deployed to the blockchain.

  • In each environment, you will be using one of three networks:

    • Mainnet: the production network where all the action happens. Transactions cost real money.
    • Testnet: used for stress testing recent releases. Focused on network performance, stability, and validator behavior.
    • Devnet: the primary network for development (these tokens have no financial value).


Development Lifecycle


  1. Set up the development environment with a local blockchain cluster.

  2. Create a filesystem wallet and airdrop Solana tokens to it.

  3. Write programs.

    • Programs export a known entrypoint symbol which the Solana runtime looks up and calls when invoking a program.
  4. Compile the program (down to Berkley Packet Filter byte-code that will then be deployed to the blockchain).

  5. Generate the program's public address (a new unique keypair, on which the pubkey is the program_id).

  6. Deploy the program to the selected blockchain cluster by creating transactions containing the program's byte-code.

  7. Once the entire program is in the blockchain, a final transaction is sent to write all of the buffered byte-code to the program's data account.

    • This either marks the new program as executable or completes upgrading an existing program.


Install Required Packages


Dependencies



Install the solana-cli


  • Install solana-cli using these instructions. This will provide commands for:

    • creating and managing file-system Solana wallets/keypairs
    • connecting to Solana clusters
    • building Solana programs
    • deploying your programs to the blockchain
  • Install the Anchor framework using these instructions.


Setting up a localhost Blockchain Cluster


  • You can run a full blockchain cluster on your machine and configure solana-cli to use it with these commands:
solana-test-validator
solana config set --url localhost

Creating a File System Wallet and Airdrop Solana tokens


  • To deploy a program with Solana CLI, you need a Solana wallet with SOL tokens.

  • To create a simple file system wallet (at ~/.config/solana/id.json) to use during local developments, type:

solana-keygen new

  • You can set your new wallet as the default:
solana config get -k ~/.config/solana/id.json
  • Aidrop testing Solana tokens:
solana airdrop 10
solana balance


Cluster and Public RPC Endpoints


  • The Solana blockchain has several different groups of validators, known as Clusters.

  • Each serves different purposes within the ecosystem and contains dedicated API nodes to fulfill JSON-RPC requests.

  • The individual nodes within a Cluster are owned and operated by third parties, and each has a public endpoint.

  • The Solana Labs organization operates a public RPC endpoint for each Cluster. Each of these public endpoints is subject to rate limits.

  • You can check your local config with:

solana config get

Config File: ~/.config/solana/cli/config.yml
RPC URL: http://localhost:8899
WebSocket URL: ws://localhost:8900/ (computed)
Keypair Path: ~/.config/solana/id.json 
Commitment: confirmed

Devnet


  • Devnet serves as a playground for devs.

  • Gossip endpoint at entrypoint.devnet.solana.com:8001.

  • Devnet endpoint: https://api.devnet.solana.com.

  • From the CLI, one can connect with:

solana config set --url https://api.devnet.solana.com

Testnet


  • Testnet serves as Solana's core contributors stress test.

  • Gossip endpoint at entrypoint.testnet.solana.com:8001.

  • Devnet endpoint: https://api.testnet.solana.com.

  • From the CLI, one can connect with:

solana config set --url https://api.testnet.solana.com

Mainnet


  • Solana's permissionless, persistent cluster.

  • Gossip endpoint at entrypoint.mainnet-beta.solana.com:8001.

  • Devnet endpoint: https://api.mainnet-beta.solana.com.

  • From the CLI, one can connect with:

solana config set --url https://api.mainnet-beta.solana.com


Demos


Backend Demo 1: Hello World



Frontend Demo 1: Interacting with the Blockchain




Useful solana-cli Commands


  • Showing a program account:
solana program show <ACCOUNT_ADDRESS>

  • Getting information about any transaction:
solana confirm -v <TRANSACTION_HASH>

  • Getting the public key:
solana-keygen pubkey

  • Redeploy a Solana Program:
solana program deploy <PROGRAM_FILEPATH>
  • If a program has been deployed, and redeployment goes beyond the max_len of the account, it's possible to extend the program to fit the larger redeployment:
solana program extend <PROGRAM_ID> <ADDITIONAL_BYTES>


Useful Solana Dev Resources


  • @solana/web3.js: a library with many basic Solana tools to interact, send transactions, and read from the blockchain.

  • @solana/spl-token: a library that contains many of the js/ts bindings needed to interact with SPL tokens. You can use this library to mint new tokens, transfer tokens, etc.

  • wallet-adapter: is a collection of libraries that help bootstrap wallet collections within Solana (such as Phantom, Solflare, and more).

  • VSCode's rust analyzer: support for the Rust such as code completion, references, workspace symbol search, semantic syntax highlighting, etc.

  • Seahorse's examples: Seahorse's compiler generates intermediate Rust artifacts and uses Anchor for the heavy lifting.



Resources