Kick-Start Solana Programming with Anchor

Search for a command to run...

No comments yet. Be the first to comment.
https://youtu.be/z4TzkuKLWAA Transcript Intro Hey, this is Sohrab, head of engineering for Lab Eleven. Today, I want to go through the basics of Solana transactions and I will be using Better Call Sol as a visual aid. You can find me on Twitter by ...

Logging can be expensive for programs deployed to Solana or logs may contain sensitive information that should not be available during the normal operation of a program. In these scenarios, we miss having different log levels, as we are used to with...

This article has been written with Anchor v0.24.x in mind. We will endeavour to keep this information updated as things evolve. Anchor framework is quickly becoming the de facto approach to building Solana on-chain programs. Its abstractions offer s...

We’ve written about why we’re getting behind the web3 movement, and our ambition to become the world’s best Solana delivery partner. Like any startup, success depends on focus, and our focus is Solana. But the question remains - why are we putting al...

Jumping into Solana programming can seem somewhat daunting. These tips and pointers should help you along with your exciting new chapter.
The book already calls out the required software for building Anchor programs.
I highly recommend Linux, macOS or Windows Subsystem for Linux v2 (WSL2) as the development environments.
For IDE, Visual Studio Code provides the optimal development experience at the best price (free!). Here are my suggestions for VS Code extensions to install:
TypeScript support comes out of the box. Some other nice-to-have extensions include Better TOML, Prettier and Remote - WSL (mandatory if working on WSL2).
I should note if you are more comfortable with the JetBrains extended universe, Rust support can be installed into your IDE as well. However, to enable Rust debugging, you will need CLion or other paid variants with Native Debugging Support.
If you are after an IntelliJ IDE that has both Rust and TypeScript support, you are limited to the paid IntelliJ IDEA Ultimate.
Anchor projects are made up of a Cargo workspace, as specified in the root Cargo.toml file, and one or more programs in their own Cargo crates, as specified in programs/*/Cargo.toml.
rust-analyzer currently only supports one Cargo workspace per VS Code workspace by default. You may face errors like the below if you open a mono-repo with multiple Anchor projects in it.
[ERROR rust_analyzer] failed to find any projects in [AbsPathBuf("...")]
[ERROR rust_analyzer::lsp_utils] rust-analyzer failed to discover workspace
The recommended way to get around this is to turn off the project auto-discovery of the plugin and specify each Anchor project manually. This can be done in .vscode/settings.json of your VS Code workspace:
{
"rust-analyzer.linkedProjects": [
"an_anchor_project/Cargo.toml",
"another_anchor_project/Cargo.toml"
]
}
Rust programming can be one of the bigger hurdles when moving into the Solana ecosystem, especially if you do not have a system programming background.
Everyone learns differently so I cannot possibly recommend one efficient way to get upskilled. But here are some tips:
I personally find the first two options more effective. As someone who knows a few programming languages already, I can skip and skim through chapters and only learn what I do not already know.
Regardless of how you learn, you do not need to learn every aspect of Rust to be a Solana developer (though I highly recommend learning as much as you can - Rust is a great language!). Here are some topics to focus on:
Box<> Here are some topics that are either not applicable or you will not need at the beginner or even intermediate level:
Anchor documentation is evolving rapidly and is actively being updated. Please keep that in mind when reading this section.
Anchor framework is a good on-ramp onto Solana development since it provides a few safety nets and ergonomics that you may miss otherwise.
A quick search will bring up a raft of tutorials written by the community. Most of them cover the basics well. The only thing to watch out for is the date when the tutorial was published. Some of the older ones may no longer be valid.
The Anchor book itself is a good starting place that covers topics in a mix of theory and practice. It is missing some topics and could use a few runs of edit but otherwise, it is great.
I personally learn more from fully working examples so Anchor GitHub repo is the place to spend time in:
examples folder contains the accompanied code for the tutorials of the now deprecated original documentation.tests folder, covering a wide range of topics.The tests are set up differently than normal Anchor projects. If you want to run them locally, consult the repo's GitHub Actions for hints.
So far, we haven't spoken much about learning Solana itself. There is a lot to learn there, that will require its own post. But in the meanwhile, I would at the minimum recommend getting your head around the basics via either their official docs or the cookbook.
As is the case with any other project in this space, the community is motivated for the projects to succeed so there is plenty of support available.
Anchor Discord is quite active and both users and contributors are more than happy to help each other out. Following Anchor on Twitter can also be worthwhile to keep on top of the latest updates.
Solana has recently achieved sufficient commitment for a StackOverflow site so hopefully soon, there will also be a specialised Q&A site to make community support even smoother!