On Solana, the code that runs on-chain is usually written in Rust. If the word "Rust" sounds intimidating, don't worry — this article introduces what an on-chain program actually is and the core patterns behind it, without assuming you are already a Rust expert.
What "smart contract" means here
On some networks the on-chain code is called a smart contract. On Solana it is simply called a program. A program is a piece of code, deployed to the network, that transactions can call to read and change on-chain data. It does not hold its own data in the way you might expect — instead it operates on the accounts passed to it.
Why Rust
Solana programs are compiled to a low-level format the network can execute efficiently, and Rust is the main language used to write them. Rust is popular here for two reasons: it produces fast, compact code, and its strict compiler catches many mistakes before your program ever runs — a valuable property when the code will manage real value.
The core pattern
Most programs follow the same shape:
- An entry point receives an instruction and the list of accounts it is allowed to touch.
- The program checks those accounts — are they the right ones, and does the caller have permission?
- It reads the current state from the relevant accounts.
- It applies its logic and writes the updated state back.
Almost every program, however complex, is a variation on this read-check-update loop.
State lives in accounts, not the program
This is the idea newcomers most often trip over. The program itself is stateless code. All the data it works with — balances, records, settings — lives in separate accounts that are passed into each call. Keeping code and state apart is what allows Solana to run many transactions in parallel, as covered in our architecture article.
Do you have to write it all by hand?
You can, and doing so once is a great way to learn. In practice, most developers use the Anchor framework to handle the repetitive validation and serialisation work, so they can concentrate on the logic that makes their program unique. Our article on Anchor explains exactly how that works.
Language tooling and on-chain program APIs change over time — always confirm current details against the official Solana and Rust documentation before building.
Want the next article in your inbox?
We run free live webinars and publish new explainers regularly. Sign up and we'll let you know.
Register for the webinar