Introduction to Anchor
What is Anchor?
Anchor is a decentralized finance (DeFi) platform built on the Solana blockchain network. It allows for seamless transactions between different DeFi applications and services, creating a unified DeFi ecosystem. Anchor enables users to trade, borrow, lend, and earn interest on digital assets, all through a single platform. Additionally, Anchor's use of Solana's high-speed blockchain infrastructure ensures fast and efficient transactions.
Installing Anchor
Anchor version manager is a tool for using multiple versions of the anchor-cli. It will require the same dependencies as building from source. It is recommended you uninstall the NPM package if you have it installed.
Install
avm
using Cargo. Note this will replace youranchor
binary if you had one installed.
cargo install --git <https://github.com/coral-xyz/anchor> avm --locked --force
Install the latest version of the CLI using
avm
, and then set it to be the version to use.avm install latest avm use latest
Verify installation
anchor --version
Creating a Project
To initialize a new project, simply run:
anchor init <new-workspace-name>
This creates a new anchor workspace you can move into. The following are some of the important files in the folder:
The
.anchor
folder: It includes the most recent program logs and a local ledger that is used for testingThe
app
folder: An empty folder that you can use to hold your frontend if you use a monorepoThe
programs
folder: This folder contains your programs. It can contain multiple but initially only contains a program with the same name as<new-workspace-name>
. This program already contains alib.rs
file with some sample code.The
tests
folder: The folder that contains your E2E tests. It will already include a file that tests the sample code in theprograms/<new-workspace-name>
.The
migrations
folder: In this folder you can save your deploy and migration scripts for your programs.The
Anchor.toml
file: This file configures workspace wide settings for your programs. Initially, it configuresThe addresses of your programs on localnet (
[programs.localnet]
)A registry your program can be pushed to (
[registry]
)A provider which can be used in your tests (
[provider]
)Scripts that Anchor executes for you (
[scripts]
). Thetest
script is run when runninganchor test
. You can run your own scripts withanchor run <script_name>
.
Last updated