Stateless Programs
Programs contain logic only. All durable state lives in program-owned accounts. This separation enables upgrades without migrating embedded storage and unlocks Sealevel parallelism.
Recipe
#[account]
pub struct Config { pub admin: Pubkey }
// Program binary never stores Config inlineWhen 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
#[program]
pub mod app {
pub fn set_admin(ctx: Context<SetAdmin>) -> Result<()> {
ctx.accounts.config.admin = ctx.accounts.admin.key();
Ok(())
}
}What 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.