The Program Entrypoint
The entrypoint receives the instruction data byte slice and a slice of AccountInfo. Anchor's #[program] macro generates dispatch from the 8-byte discriminator to your handlers.
Recipe
use anchor_lang::prelude::*;
#[program]
pub mod my_program { /* handlers */ }When to reach for this:
- Building or debugging on Agave 4.1.1
- Integrating with Anchor 0.32.1 programs
- Client work with @solana/kit 7.0.0
Working Example
// Native (without Anchor):
// entrypoint!(process_instruction);
// fn process_instruction(program_id, accounts, data) -> ProgramResultWhat this demonstrates:
- Idiomatic patterns for the Agave 4.1 era
- Correct account and signer handling
- Observable behavior via logs or RPC
Deep Dive
How It Works
- Solana programs execute in the Sealevel parallel runtime
- Transactions declare all accounts; non-overlapping work runs in parallel
- Compute is metered in CUs; rent-exempt accounts persist state
Gotchas
- Stale web3.js v1 examples - use @solana/kit 7.0.0. Fix: migrate client code.
- Missing signer flags - txs fail at runtime. Fix: mark signers explicitly.
- Expired blockhash on retry - silent drops. Fix: refresh and re-sign.
- Wrong cluster RPC - accounts not found. Fix: match cluster end-to-end.
- Undersized account space - init fails. Fix: use InitSpace in Anchor 0.32.1.
Alternatives
| Alternative | Use When | Don't Use When |
|---|---|---|
| Anchor 0.32.1 | Rapid development | Minimal native BPF |
| Native Rust | Maximum control | Fast iteration needed |
| LiteSVM 0.6.x | Unit tests | Network integration tests |
| Surfpool 0.12.0 | Anchor integration tests | One-off CLI tasks |
FAQs
How does this relate to Sealevel?
See sections above for detail.
What CLI version should I use?
See sections above for detail.
Does this apply to mainnet-beta?
See sections above for detail.
What commitment level should clients use?
See sections above for detail.
How do I debug failures?
See sections above for detail.
Are PDAs involved?
See sections above for detail.
What about compute units?
See sections above for detail.
Can I use devnet?
See sections above for detail.
How do upgrades work?
See sections above for detail.
What replaces web3.js?
See sections above for detail.
How do I test locally?
See sections above for detail.
What is Agave 4.1.1?
See sections above for detail.
Related
Stack versions: This page was written for Agave 4.1.1, Solana CLI 3.0.10, Anchor 0.32.1, anchor-lang 0.32.1, Rust 1.91.1, @solana/kit 7.0.0, Surfpool 0.12.0, and LiteSVM 0.6.x.