In this post, we’ll continue from where we left off in the last guide Setting Up Local Solana Environment. We’ve already set up our Solana development environment, so now, let’s run our first Solana project using the default Anchor code. By the end of this post, you’ll know how to set up your IDE, connect to WSL, and deploy your first Solana program on the Devnet.
Step 1: Install Visual Studio Code (VS Code)
VS Code is one of the best editors for Solana development. If you don’t already have it installed, download and install it from Visual Studio Code's official website.
Step 2: Install Remote - WSL Extension
The Remote - WSL extension allows you to seamlessly work with files and folders inside your WSL Ubuntu environment.
- Open VS Code.
- Go to the Extensions view by clicking the Extensions icon on the left-hand side or pressing
Ctrl+Shift+X
. - Search for
Remote - WSL
and click Install.
Step 3: Connect VS Code to WSL Ubuntu
After installing the extension, connect to the Ubuntu environment we created in the previous guide:
- Open the Command Palette (
Ctrl+Shift+P
) in VS Code. - Search for and select Remote-WSL: New Window.
- This opens a new VS Code window connected to your WSL environment.
Step 4: Install Rust Analyzer Extension
Rust Analyzer provides powerful features like syntax highlighting, autocompletion, and inline documentation for Rust projects.
- In the Extensions view (
Ctrl+Shift+X
), search forRust Analyzer
. - Click Install.
Step 5: Generate a Default Anchor Project
Anchor provides a boilerplate project to help you start coding quickly. Follow these steps to create your first Solana program:
- Open the WSL terminal in VS Code or launch it from your Ubuntu environment.
- Run the following commands to initialize a new project:
anchor init my_solana_project
cd my_solana_project
This creates a new directory with a basic Solana program scaffold.
Step 6: Build the Anchor Project
Before deploying, we need to build the program:
- Navigate to the project directory if you're not already there:
cd my_solana_project
- Build the project:
anchor build
This compiles the Rust code into a Solana-compatible program.
Step 7: Run Solana Test Validator
solana-test-validator starts a local Solana network on your machine, which allows you to deploy and test your Anchor program without relying on the Solana devnet or mainnet.
We will run the below command
solana-test-validator
If you encounter an error with the above command run
solana-test-validator --log
If you encounter errors like "AVX2 not supported", refer to the Solana GitHub repository for instructions on building Solana from source.
Step 8: Get Sol for Gas Fees
To deploy your program, you’ll need some SOL to cover transaction fees. Let’s request SOL from the Devnet faucet:
- Set your Solana CLI to use the Devnet:
solana config set --url https://api.devnet.solana.com
- Generate a new Solana wallet:
solana-keygen new --outfile ~/.config/solana/id.json
- Fund your wallet with Devnet SOL:
solana airdrop 2
- Confirm your balance:
solana balance
Step 9: Deploy the Anchor Program
Now that everything is ready, deploy the program to the Devnet:
- Run the deployment command:
anchor deploy
- After a successful deployment, you’ll see the program ID in the output. Save this ID for later use.
Step 10: Interact with Your Deployed Program (Optional)
Anchor provides a test suite for interacting with your program. To test the default code:
- Run the test command:
anchor test
- This executes the default program logic on the Devnet and returns the results.
Additional Tips:
-
Use
.env
Files: Store your program ID, RPC URL, and other secrets in a.env
file to keep your project organized. -
Debugging: If you run into errors, check the
target/deploy
folder for compiled artifacts and logs. - Read the Docs: Explore Anchor’s official documentation for advanced topics like program state and cross-program invocations.
- Error Handling: If you encounter deployment errors, check the logs in the target/deploy/ folder.
- Local vs. Devnet: Use solana-test-validator for local testing. Switch to Devnet when interacting with real wallets or external users.
- Documentation: Explore Anchor's official docs for advanced features like program state and cross-program invocations.
Conclusion
Congratulations! You’ve successfully run your first Solana project using Anchor. From setting up VS Code to deploying on Devnet, you’ve completed the essential steps to get started with Solana development.
If you have questions or want to learn more, subscribe and stay tuned for the next guide where we’ll dive deeper into customizing Anchor programs.
Top comments (0)