Instruction Arguments
Arguments after Context<T> are Borsh-serialized in instruction data. Use #[instruction(...)] on accounts structs to reference args in constraints.
Search across all documentation pages
Arguments after Context<T> are Borsh-serialized in instruction data. Use #[instruction(...)] on accounts structs to reference args in constraints.
#[derive(Accounts)]
#[instruction(amount: u64, recipient: Pubkey)]
pub struct Transfer<'info> { /* use amount in constraint */ }
pub fn transfer(ctx: Context<Transfer>, amount: u64, recipient: Pubkey) -> Result<()> {
require!(amount > 0, MyError::InvalidAmount);
Ok(())
}When to reach for this: Clients pass numeric or pubkey parameters beyond the account list.
#[derive(Accounts)]
#[instruction(id: u64)]
pub struct CreatePool<'info> {
#[account(
init,
payer = payer,
space = 8 + Pool::INIT_SPACE,
seeds = [b"pool", id.to_le_bytes().as_ref()],
bump,
)]
pub pool: Account<'info, Pool>,
#[account(mut)]
pub payer: Signer<'info>,
pub system_program: Program<'info, System>,
}
pub fn create_pool(ctx: Context<CreatePool>, id: u64, fee_bps: u16) -> Result<()> {
require!(fee_bps <= 10_000, PoolError::InvalidFee);
ctx.accounts.pool.fee_bps = fee_bps;
Ok(())
}What this demonstrates:
#[instruction] exposes args to constraintsrequire! earlyAnchor prepends 8-byte instruction discriminator, then Borsh-encodes args in handler parameter order.
checked_add/checked_mul.| Alternative | Use When | Don't Use When |
|---|---|---|
| Accounts-only API | When every input is on-chain state | Client-supplied scalars |
| Instruction data manually (native) | Non-Borsh layouts | Anchor IDL workflows |
| Version byte prefix in custom layout | Migration of arg layout | Greenfield Anchor programs |
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 args 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 16, 2026