Anchor is a framework for Solana’s Sealevel runtime providing several convenient developer tools.
Reference: Getting started with Solana and Anchor
- install rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
export PATH="$HOME/.cargo/bin:$PATH"
- install solana
sh -c "$(curl -sSfL https://release.solana.com/v1.11.10/install)"
export PATH="$HOME/.local/share/solana/install/active_release/bin:$PATH"
- install anchor
cargo install --git https://github.com/project-serum/anchor anchor-cli --locked
anchor --version
- install yarn
npm install -g yarn
yarn install
- solana config
URL for Solana's JSON RPC [mainnet-beta, testnet, devnet, localhost]
solana config set --url localhost
- getnerate key pair
solana-keygen new
solana address
run a local ledger for development and testing.
# Check you can run a local validator (Run Ctrl+C to exit).
# Note this creates a "test-ledger" folder in your current directory.
sudo solana-test-validator
# Or, run a new empty local ledger.
sudo solana-test-validator --reset
cd router-solana-contract
sudo anchor build
Once our code was compiled, the target
folder was updated accordingly.
The target
folder basically keeps track of any built releases and deployment of our program.
Especially
target/deploy
The first time you build a program, it will also generate a public and private key for it — which will be stored in the
target/deploy
directory. The public key generated will become the unique identifier of your program (the program ID). It also inclue a.so
file which is the compiledBPF
program.
target/idl
simply a JSON file that contains all the specifications of our Solana program
We can access our program ID by using the following Solana command.
solana address -k target/deploy/router-keypair.json
# Outputs something like: 5F3j1TvB7CQa4XRFN48iAd8y2ZgXXzUTVMJvtFXvF4N
Okay now that we know our program ID, let's update it.
First, in our Anchor.toml
configuration file.
[programs.localnet]
router = "5F3j1TvB7CQa4XRFN48iAd8y2ZgXXzUTVMJvtFXvF4N"
Then, in the lib.rs file of our Solana program.
that's programs/router/src/lib.rs
.
declare_id!("5F3j1TvB7CQa4XRFN48iAd8y2ZgXXzUTVMJvtFXvF4N");
sudo anchor build
sudo anchor test --skip-local-validator
sudo anchor deploy
sudo anchor deploy --provider.cluster https://api.testnet.solana.com/
use tools to swapin and mint token
node app/client.js -h