Anchor CLI Basics
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 basic Rust program and TypeScript test template.
$anchor init my-project
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.
When running anchor build, if you encounter the following errors:
After applying the preceding solution, attempt to run anchor build
again.
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.
Either of the following errors may indicate that you don't have Node.js or Yarn installed:
Permission denied (os error 13)
No such file or directory (os error 2)
Is this page helpful?