The Anchor Workflow
Use this decision workflow from idea to deployed instruction: local build, test, simulate, then promote to devnet and mainnet.
How to Use This Workflow
- Follow steps in order for new instructions; skip ahead only for doc-only changes.
- Never deploy to mainnet without passing local and devnet test suites.
- Regenerate IDL after every public API change.
- Record program ID and IDL hash in your release notes.
Step 1: Are you changing on-chain logic?
Yes → edit programs/*/src/lib.rs, update account structs, and add tests.
No → client-only change: update TS client against existing IDL; skip redeploy.
Step 2: Does the change need a new account layout?
If yes, plan migration or realloc. Add space on init and version your account struct. See realloc in Anchor.
Step 3: Run anchor build
Fix compile errors and macro expansion issues. Confirm target/idl/*.json updated.
Step 4: Run anchor test locally
Surfpool or local validator exercises deploy + TS tests. Add cases for new errors and edge seeds.
Step 5: Do tests pass?
No → fix program or test fixtures; use solana logs or Surfpool traces.
Yes → proceed to devnet.
Step 6: Deploy to devnet
anchor deploy --provider.cluster devnet. Run integration tests against devnet RPC or LiteSVM with fetched accounts.
Step 7: Update clients and IDL consumers
Publish IDL, run Codama/declare_program! refresh, bump npm package if applicable.
Step 8: Security review needed?
New signers, CPIs, or init_if_needed → request review. See CPI Safety.
Step 9: Ready for mainnet?
Verifiable build, audited diff, funded upgrade authority, and rollback plan. Deploy with same anchor deploy flow on mainnet provider.
FAQs
What Anchor version does this site use?
0.32.1 for anchor-lang, Anchor CLI, and examples in this section.
Do I need Solana CLI alongside Anchor?
Yes. Solana CLI 3.0.10 handles keypairs, airdrops, and solana program inspection.
Where does the IDL live after build?
target/idl/<program>.json in your workspace.
Can I mix UncheckedAccount with Signer?
Yes, but every unchecked field needs explicit constraints or handler checks.
How do I test without devnet?
Use anchor test with Surfpool 0.12.0 or LiteSVM 0.6.x in CI.
What is the 8-byte prefix on account data?
Anchor account discriminator; do not strip it when sizing space.
Should I commit generated IDL?
Yes, or publish on-chain IDL so clients have a canonical source.
How do I debug constraint failures?
Run with logs; Anchor prints constraint name and account index.
Does Anchor work on Agave 4.1.1?
Yes. This stack targets Agave validators with Solana CLI 3.0.10.
What should I read next in this section?
See sibling articles linked in Related for deeper workflow topics.
Related
- Building & Deploying - commands
- Anchor Basics Best Practices - habits
- Anchor TS Tests - test patterns
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.