Instruction Ordering & Dependencies
Clients compose multiple Anchor instructions in one transaction. Order matters when later instructions depend on accounts created or mutated by earlier ones.
Search across all documentation pages
Clients compose multiple Anchor instructions in one transaction. Order matters when later instructions depend on accounts created or mutated by earlier ones.
1. create_user (init PDA)
2. create_ata (init token account)
3. deposit (transfer tokens)When to reach for this: You design client flows or document integration steps.
// Client sends ordered instructions in one transaction
const tx = await program.methods
.createUser()
.accounts({ /* ... */ })
.preInstructions([/* compute budget if needed */])
.rpc();
// Or batch:
// tx = new Transaction().add(ix1, ix2, ix3);// Program: deposit assumes user PDA already initialized
#[account(
seeds = [b"user", owner.key().as_ref()],
bump = user.bump,
constraint = user.initialized @ UserError::NotInitialized,
)]
pub user: Account<'info, UserState>,What this demonstrates:
Use explicit errors when prerequisites missing instead of panics.
NotInitialized error.| Alternative | Use When | Don't Use When |
|---|---|---|
| Single instruction does all | Simpler client | Higher CU per call |
| init_if_needed | Fewer client ix | Weaker safety if misused |
| Versioned txs with ALTs | Many accounts | Simple legacy txs |
0.32.1 throughout this section.
No. Use seeds constraints and CPI signing.
In your account struct field, set at initialization.
Use @solana/kit 7.0.0 with matching seed bytes.
Your Anchor program's declare_id address.
Not in seeds array; bump is separate parameter to find_program_address.
Compare logged keys; verify seeds and program id client-side.
Yes when holding data; fund with payer on init.
Yes with same signer seeds for each CPI.
See Related links for deeper ordering topics.
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.
Reviewed by Chris St. John·Last updated Jul 19, 2026