Zero-to-Hero on Solana
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
- Install NPM directly
sudo apt update
curl -sL https://deb.nodesource.com/setup_14.x | sudo bash -
sudo apt -y install nodejs - 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
- 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 - Get access to rustup command:
source $HOME/.cargo/env
- Confirm we have rustfmt:
rustup component add rustfmt
- Install Solana, around 240MB:
sh -c "$(curl -sSfL https://release.solana.com/v1.9.8/install)"
- Get access to solana
source ~/.profile
- Confirm access to solana library
solana --version
- Install linux requirements for anchor
sudo apt-get install -y pkg-config build-essential libudev-dev libssl-dev
- Install Anchor
cargo install --git https://github.com/project-serum/anchor --tag v0.23.0 anchor-cli --locked
- Install mocha & Anchor for npm, used unit/integration tests
npm install -g mocha
npm install -g @project-serum/anchor - Confirm anchor is available globally
anchor --version
D. Solana Keys, Validator, and Devnet Airdrop
- Open another terminal and get into the VM (
multipass shell zerotosolana
) to generate a walletsolana-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
- 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
- Get your pubkey address
solana-keygen pubkey
- Get an Airdrop of 10 SOL on devnet
solana --url devnet airdrop 10
- Edit
Anchor.toml
and changelocalnet
todevnet
, so it looks like this[provider]
cluster = "devnet"
wallet = "~/.config/solana/id.json"
[scripts]
test = "mocha -t 1000000 tests/" - Run
anchor build
if you haven’t already from the previous section - 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
- Multipass: https://multipass.run/
- Anchor: https://project-serum.github.io/anchor/getting-started/installation.html
- Hero image: Ruth Troughton, https://unsplash.com/photos/MenMX04sh_A
- WSL install on Windows
https://www.omgubuntu.co.uk/how-to-install-wsl2-on-windows-10