Anchor Framework

The most popular development framework for Solana programs, providing Rust macros, built-in security checks, and auto-generated interfaces that strip away boilerplate and help developers ship secure code dramatically faster.

What is the Anchor Framework

Anchor stands as the standard Rust framework for building Solana programs. Developed by Armani Ferrante, who is also the founder of Coral (which also built the Backpack wallet), Anchor builds upon the existing Solana runtime by adding Rust macros to automatically generate boilerplate code. This handles the repetitive checks that all secure programs need to perform, leaving you only to write your program's business logic instead of constantly verifying accounts.

Think of Anchor as the software equivalent of tax-filing assistance. When you file your taxes, you could either fill every form by hand, checking complex regulations and ensuring that you haven't missed any fields in the process or you could simply answer some questions while the software fills in the forms, runs all the checks, and won't let you file until all required fields are filled. Anchors macros do this same thing for Solana programs. They know which checks are required, and you just have to tell them which accounts to check.

How Anchor Works Technically

Solana programs are stateless. You must explicitly pass the data a program needs in the form of accounts within a transaction, and the runtime doesn't know anything about that data and doesn't verify it for you. A program written purely in native Rust will have to manually check the owner and type of every account it touches, along with checking all the required signers, missing any of which is the most common source of exploitable errors in Solana applications. Anchor's macros allow you to convert these checks into constraints that are checked by generated code. You simply declare the constraints required of an account, and the generated program code ensures that your code never runs if any of those conditions aren't met.

Additionally, Anchor creates a standard way for clients to interact with your program by adding a discriminator, an 8-byte integer tag based on the instruction name, to every instruction in your program. Anchor will also produce an Interface Definition Language (IDL) in JSON format describing all of the instructions and accounts for use by a framework client such as those built into TypeScript, making it easier to call a program by name instead of packing all of the necessary bytes yourself. Finally, Anchor has an in-built testing tool called anchor test that can take care of building a program, spinning up a test validator, and deploying the program while running your tests against it all in one step.

How Anchor Compares to Ethereum Tooling

If you're coming over from an Ethereum development perspective, you might best understand Anchor as a combination of Hardhat plus OpenZeppelin combined into a single framework. Where Hardhat gives a Solidity developer a compilation and testing environment that abstracts away the details of the Solidity compiler, OpenZeppelin is a set of pre-written code and auditing patterns that deal with some of the most common security errors. Anchor is both of these combined, and it is even more important on Solana than it is on Ethereum. The difference between writing Solidity code and writing Ethereum-compatible code is smaller than it is between writing Solana native Rust and writing an Anchor program. Solidity code is compiled into bytecode by a compiler that understands a strict storage layout, and the Ethereum Virtual Machine provides some type checking at the level of the protocol. Anchor, on the other hand, runs on top of the Solana VM, which provides absolutely no information about how the accounts passed to your program are related to each other.

Imagine an Ethereum developer wants to port their ideas for a perp trading dApp to Solana. In a raw Rust program, the developer would be forced to write out dozens of checks to see whether every account that comes into the program has the required ownership and signatures, and any one of those checks being wrong would make their app drainable. In an Anchor program, the developer writes out a constraint for every account and the generated program code checks every one. This is one of the primary reasons that a number of established DeFi protocols like Drift's perp-ex change use Anchor, even though you don't have to write an Anchor program on Solana.

Why Anchor Matters

Anchor does come with a cost in the form of additional compute usage as the program will execute the generated checks to verify the accounts before running, and a slightly larger program binary than a pure Rust program. Additionally, some security auditors will dislike a macro-generated program because the security checks are all written out by a macro, so they can't be seen in the source code itself. Those projects trying to save as much compute as possible still use raw Rust to make sure of it.

However, for the overwhelming majority of people, Anchor is essential for developing on Solana. The most prevalent class of exploit on Solana, which is an incorrect account check, will now be caught by the automatically generated code before a tired human misses it at 2 a.m. The IDL output allows explorers and even wallet extensions to read a program's data for the user rather than presenting the user with raw bytes that they won't understand. Finally, Anchor has a built-in testing framework that makes the process of going from scratch to a tested Solana program deployable on the devnet much easier, which will look very familiar to anyone coming over from using Foundry on Ethereum.

Do you have to use Anchor to build on Solana?

There is absolutely no requirement to use Anchor, and programs written in pure Rust do exist and continue to exist today, but almost everyone uses it today and it's probably a safe assumption that you will want to use it to build your program, especially in 2026 where you can't really expect yourself to get away with not validating every input.

Contents

Writen By

Stay Updated - Follow us on X

Project review threads, dApp insights, announcements, news, and more.