Client-Side PDA Derivation
Clients must derive the same PDAs as on-chain seeds constraints. Use identical seed bytes, order, and program ID.
Search across all documentation pages
Clients must derive the same PDAs as on-chain seeds constraints. Use identical seed bytes, order, and program ID.
import { getAddressEncoder, getProgramDerivedAddress } from "@solana/kit";
const addressEncoder = getAddressEncoder();
const [pda] = await getProgramDerivedAddress({
programAddress: programId,
seeds: ["escrow", addressEncoder.encode(maker), u64ToLeBytes(escrowId)],
});When to reach for this: Building transactions that pass PDA accounts to Anchor instructions.
import { address, getAddressEncoder, getProgramDerivedAddress } from "@solana/kit";
const programId = address("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
// u64 -> 8 bytes little-endian, explicitly. Do not rely on the host's
// native byte order via BigUint64Array#buffer.
function u64ToLeBytes(value: bigint): Uint8Array {
const bytes = new Uint8Array(8);
new DataView(bytes.buffer).setBigUint64(0, value, true);
return bytes;
}
const [escrowPda] = await getProgramDerivedAddress({
programAddress: programId,
// getAddressEncoder turns a base58 Address into its 32 raw bytes.
// getBytesEncoder would NOT do this - it only passes bytes through.
seeds: [
new TextEncoder().encode("escrow"),
getAddressEncoder().encode(makerAddress),
u64ToLeBytes(BigInt(escrowId)),
],
});
// Pass escrowPda in accounts map matching IDL name "escrow"What this demonstrates:
b"escrow" bytesto_le_bytesUse kit helpers for PDA derivation and address encoding. Share seed builders between program (Rust constants) and client (TS module) via codegen or documented constants.
Assert client PDA matches anchor test fixtures for every seed variant.
to_le_bytes.| Alternative | Use When | Don't Use When |
|---|---|---|
| Anchor TS client .pda helpers | Legacy @coral-xyz/anchor | Greenfield @solana/kit |
| Codama-generated PDAs | From IDL seeds metadata | Hand-rolled seed math |
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 client pda 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