- Blockchain layer
- Anchor framework
- Solana localhost network
- Frontend layer
- Next framework with React library (17.xxx)
- TypeScript language
- Tailwind CSS framework
- daisyUI: Tailwind CSS UI component library
- Immer: Immutable data structure for state management
- Backend layer - TBD
- Data layer (Oracle) - TBD
-
Rust compiler :
curl https://sh.rustup.rs -sSf | sh\n
-
Solana tool suit :
sh -c "$(curl -sSfL https://release.solana.com/v1.10.8/install)"
-
Anchor version manager:
cargo install --git https://github.com/project-serum/anchor avm --locked --force
-
Anchor
framework:avm install latest avm use latest
-
Solana project structure
app
: front-end codeprograms
: solana programtest
: javascript / typescript test for solana programmigration
: basic deploy script
-
lib.rs
structuredeclare_id!("77iNmGEeh3ks2XSkGCaHeYeePhNGn1Dei2CEMkAssFx9");
: program address. Program execution begin with a transaction submitted to the cluster, transaction may include one or more instructions.#[program]
: define program that handle logic via set of instruction handler function (RPC handler). For example:pub fn create(ctx: Context<Create>) -> Result<()> {}
pub fn increment(ctx: Context<Increment>) -> Result<()>
Context
: always first param in method, is simple container over transaction instruction#[derive(Accounts)]
: define transaction instruction. For example:pub struct Create<'info>
pub struct Initialize {}
pub struct Increment<'info>
BaseAccount
: data structure - Solana Account that will be passed to transaction instruction. This struct is working as an OS file that storing data between Transaction- Inside each transaction instruction, we may have three parameters
base_account
: with#[account(init, payer = user, space = 8 + 8)]
init
: telling Anchor should create an account responding toBaseAccount
structurepayer
: indicate which account provide the token (lamports) to pay for newly created account rent. It'suser
account list next!space
: number of bytes required to store the account's data
user
: account to pay fee for renting fee, it is owner that has authorized the transactionsystem_program
: solana system program provides various services, such as creating account, transfer lamports etc.
- Solana provides some network (localhost, devnet, mainnet beta..). I suggest to use
devnet
for development / testing because i found some issue inlocalhost
withfetch
- Using command to switch between network:
solana config set --url localhost
solana config set --url devnet
- Checking current address and balance
solana address
solana balance [address]
( if you want to deploy smart contract, make sure you have enough balance)solana airdrop 1 [address]
to get more solana in your devnet walletsolana logs
: get logs from network (localhost / devnet)
- Deployment
- Getting program id:
solana address -k target/deploy/...-keypair.json
- Update
lib.rs
andAnchor.toml
with program id - Switch Fantom wallet to the
devnet
network - Run anchor commands to build / test and deploy
anchor build
- build smart contractanchor test
- running JavaScript test scriptanchor deploy
- deploy to local, make suresolana-test-validator
is running
- Getting program id:
- Home Page Screen with Fantom Wallet Connected
- Calling smart contract to get counter's value
- Failed to setup Jest in React App (compatible issue ?)
Note
Smart contract address -Program ID
: 77iNmGEeh3ks2XSkGCaHeYeePhNGn1Dei2CEMkAssFx9
- Document
- Code base
- Study more