Deriving PDAs
PDAs are derived from seeds and a program id. find_program_address returns the canonical off-curve address and bump seed required for invoke_signed.
Search across all documentation pages
PDAs are derived from seeds and a program id. find_program_address returns the canonical off-curve address and bump seed required for invoke_signed.
let (pda, bump) = Pubkey::find_program_address(
&[b"metadata", mint.key.as_ref()],
program_id,
);When to reach for this:
pub fn verify_config(config: &AccountInfo, authority: &Pubkey, program_id: &Pubkey, stored_bump: u8) -> ProgramResult {
let (expected, bump) = Pubkey::find_program_address(&[b"config", authority.as_ref()], program_id);
if expected != *config.key || bump != stored_bump {
return Err(ProgramError::InvalidSeeds);
}
Ok(())
}What this demonstrates:
InvalidSeeds on mismatch.| Constraint | Value |
|---|---|
| Seeds count | <= 16 |
| Seed len | <= 32 bytes each |
let bump_seed = [bump];
let signer_seeds: &[&[u8]] = &[b"vault", owner.as_ref(), &bump_seed];
// invoke_signed wants &[&[&[u8]]] - wrap the group once more:
invoke_signed(&ix, account_infos, &[signer_seeds])?;invoke_signed fails. Fix: Append &[bump] slice..as_bytes() consistently. Fix: Document encoding.id.to_le_bytes(). Fix: Avoid ambiguous packing.| Alternative | Use When | Don't Use When |
|---|---|---|
| create_program_address | Known bump | Unknown bump |
| Anchor seeds macro | Ergonomic | Native explicit |
| Off-chain only derivation | Save CU | Must verify on-chain |
find searches bump; create requires exact bump.
Different PDAs - by design.
Discouraged - use constant prefix.
Document; changing order changes address.
Not guaranteed - store actual bump.
@solana/kit getProgramDerivedAddress.
Snapshot pda+bump in tests.
Different semantics need different prefixes.
No if program id unchanged.
Add disambiguator seed bytes.
16 seeds per derivation.
Avoid - use stored bump.
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