I’m learning solana and rust with the fascinating turorial by Rareskills. And I ran into many issues in the process, so I decided to made a daily log to record my solana journey and meet anyone who’s interesting in learning solana. Ps: most of the contents I wrote here cames from the tutorial by Rareskills, I’m recording the issues and how I fixed it during the study process.
Join my tg! :
Ok let’s dive in day1:
Install rust and yarn
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
npm install --global yarn
Install Solana
sh -c "$(curl -sSfL https://release.solana.com/stable/install)"
Install Anchor(Solana devlopment frame)
cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
avm install latest
avm use latest
anchor init day_1
Be sure to do: anchor init day_1, not anchor init day1, use day_1 instead of day1. Cuz Anchor seems to silently insert underscores on Mac machines sometimes. Im on wsl2 of windows and still have wired things happened when named my project with day1. The error goes:
Error: target/idl/day_1.json doesn't exist. Did you run `anchor build`?
Continue to build:
cd day1
anchor build
Another error:
error[E0658]: use of unstable library feature 'build_hasher_simple_hash_one'
The solution is:
cargo update -p ahash@0.8.9 --precise 0.8.6
Draft saved
Open Settings Panel
Publish
Remove header image
0x9B05…3771
0x9B05
Draft
Another error:
error: package solana-program v1.18.0 cannot be built because it requires rustc 1.72.0 or newer, while the currently active rustc version is 1.68.0-dev
The solution is:
cargo add solana-program@=1.17.0
cargo update -p solana-program
Lets run anchor build again. And boom it build successfully!
anchor build
Configure Solana to run on localhost
solana config set --url localhost
Key sync
anchor keys sync
Run test:
anchor test --skip-local-validator
If everything went well, you’ll see:
Let’s edit the code and add one line to lib.rs
nano ./programs/day_1/src/lib.rs
use anchor_lang::prelude::*;
declare_id!("...");
#[program]
pub mod day_1 {
use super::*;
pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
msg!("Hello, world!"); // **** NEW LINE HERE ****
Ok(())
}
}
#[derive(Accounts)]
pub struct Initialize {}
And run test again:
anchor test --skip-local-validator
List the log file and open it with nano
ls .anchor/program-logs/
# you'll see the file *****.log, open it
nano .anchor/program-logs/*****.log
You’ll see
That’s it! Thanks. Join my tg if you have any problems and wants to discuss with me