This section provides some common commands and examples to help you get started using the Anchor CLI.
Initialize the project
Create a new Anchor project by running the command shown below. It will create a new directory with the project name and use it to initialize a new Anchor project.
$anchor init <project-name>
For example, the command below will create a project called my-project. The
my-project directory will contain a modular Rust program and a Rust test
template that uses LiteSVM.
$anchor init my-project
To generate a TypeScript test template instead, choose one explicitly. For example, use the Mocha template:
$anchor init my-project --test-template mocha
TypeScript test templates require Node.js and a JavaScript package manager.
Then navigate to the project directory:
$cd <project-name>
See Anchor's project file structure.
Build the program
To build your project, run the following command:
$anchor build
You can find the compiled program in the /target/deploy directory.
Platform tools failed to install
If the build reports an invalid platform-tools directory, reinstall the SBF build tools, then retry the build:
$cargo build-sbf --force-tools-install$anchor build
Deploy the program
To deploy your project, run the following command:
$anchor deploy
This command deploys your program to the cluster specified in the
Anchor.toml file.
Test the program
To test your project, run the following command:
$anchor test
This command builds, deploys, and runs the tests for your project.
When using the localnet cluster, Anchor automatically starts a local
validator, deploys the program, runs tests, then stops the validator.
JavaScript test runner errors
If you selected a JavaScript or TypeScript test template, either of the following errors may indicate that Node.js or the configured package manager is not installed:
Permission denied (os error 13)
No such file or directory (os error 2)
Is this page helpful?