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.

Terminal
$
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.

Terminal
$
anchor init my-project

Then navigate to the project directory:

Terminal
$
cd <project-name>

See Anchor's project file structure.

Build the program

To build your project, run the following command:

Terminal
$
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:

Terminal
$
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:

Terminal
$
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?

सामग्री तालिका

पृष्ठ संपादित करें

द्वारा प्रबंधित

© 2025 सोलाना फाउंडेशन। सर्वाधिकार सुरक्षित।