Zero-to-Hero on Solana

Zhaohui Li
3 min readMar 24, 2022

Going from Zero to Hero on Solana; running your first deploy with no pre-requisites

A. Introduction

Pre-requisites:

  • OS-specific: No. From laptop unboxing to deploy, regardless of Linux, Mac, or Windows(Install WSL1 or WSL2)
  • Rust knowledge: None. Will install the toolchain and get you access to the commands
  • Solana knowledge: None. Will set up the Solana keys and explain it

Goal for this is to be copy-paste in-order from a fresh system install to a deployed contract on Solana devnet, all on a single page with numbered steps (so you can get help debugging)

It includes fixes to the references (missing dependencies and out of order items) with a simpler explanations on what’s happening. See references section to dive deeper into the details.

The dependency packages will also be split up and organized by section, so you can skip ahead if you want to use your own infra to test it out.

B. Install npm in Ubuntu

  1. Install NPM directly
    sudo apt update
    curl -sL https://deb.nodesource.com/setup_14.x | sudo bash -
    sudo apt -y install nodejs
  2. Use NVM to install NPM
    sudo apt install curl
    curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh| bash
    source ~/.profile
    nvm install node
    nvm install 16
    nvm use 16

C. Install Rust toolchain, Solana toolchain & Anchor in Ubuntu

  1. Install rust, and enter 1 to proceed with default:
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    It will create ~/.cargo/env file
  2. Get access to rustup command:
    source $HOME/.cargo/env
  3. Confirm we have rustfmt:
    rustup component add rustfmt
  4. Install Solana, around 240MB:
    sh -c "$(curl -sSfL https://release.solana.com/v1.9.8/install)"
  5. Get access to solana
    source ~/.profile
  6. Confirm access to solana library
    solana --version
  7. Install linux requirements for anchor
    sudo apt-get install -y pkg-config build-essential libudev-dev libssl-dev
  8. Install Anchor
    cargo install --git https://github.com/project-serum/anchor --tag v0.23.0 anchor-cli --locked
  9. Install mocha & Anchor for npm, used unit/integration tests
    npm install -g mocha
    npm install -g @project-serum/anchor
  10. Confirm anchor is available globally
    anchor --version

D. Solana Keys, Validator, and Devnet Airdrop

  1. Open another terminal and get into the VM (multipass shell zerotosolana) to generate a wallet
    solana-keygen new
    Generating a new keypair
    For added security, enter a BIP39 passphrase
    NOTE! This passphrase improves security of the recovery seed phrase NOT the
    keypair file itself, which is stored as insecure plain text
    BIP39 Passphrase (empty for none):
    Wrote new keypair to /home/ubuntu/.config/solana/id.json
    =============================================================================
    pubkey: xiYwvdFBbYYZBu2o9CBcHZK7G7vBqdmcWAPiLs6HtHb
    =============================================================================
    Save this seed phrase and your BIP39 passphrase to recover your new keypair:
    fake seed lightcycle research is the best fake seed fake seed fake
    =============================================================================

E. Deploy Program to Localnet

  1. Clone the anchor repository to access the basic tutorials
    git clone https://github.com/project-serum/anchor --depth 1

2. Change directory into the example folder
cd anchor/examples/tutorial/basic-0

3. Build the code; this will download a 180MB SDK first:
anchor build

4. Run the deploy:
anchor deploy

F. Deploy Program to devnet

  1. Get your pubkey address
    solana-keygen pubkey
  2. Get an Airdrop of 10 SOL on devnet
    solana --url devnet airdrop 10
  3. Edit Anchor.toml and change localnet to devnet, so it looks like this
    [provider]
    cluster = "devnet"
    wallet = "~/.config/solana/id.json"
    [scripts]
    test = "mocha -t 1000000 tests/"
  4. Run anchor build if you haven’t already from the previous section
  5. Run anchor deploy and you’ll see something like this:
    Deploying workspace: https://api.devnet.solana.com
    Upgrade authority: /home/ubuntu/.config/solana/id.json
    Deploying program "basic-0"...
    Program path: /home/ubuntu/anchor/examples/tutorial/basic-0/target/deploy/basic_0.so...
    Program Id: 9Tn8HZEpS9cUtQrBcJ5BbSVcArAWpi7P2nrKdHFcakd
    Deploy success

References

--

--