SummaryPDAs are derived by hashing seeds + program ID + bump via SHA-256 until the
result is off the Ed25519 curve. The canonical bump is the first value that
produces an off-curve address. Max 16 seeds including the bump (15 of your
own), Max 32 bytes per seed.
Background
SolanaKeypair
values are points on the Ed25519 curve. A keypair
consists of a public key (used as the account address) and a secret key (used to
produce signatures). Anyone with the secret key can sign transactions for that
address.
invoke_signed.
PDA vs keypair accounts
| Property | Keypair account | PDA account |
|---|---|---|
| Address type | On Ed25519 curve | Off Ed25519 curve |
| Has private key | Yes | No |
| Can sign transactions | Yes (with private key) | No |
| Can sign during CPI | No (unless signature included in transaction) | Yes (via invoke_signed) |
| Derivation | Generate Ed25519 keypair | Deterministic from seeds + program ID |
| Typical use | User wallets, Program ID | Program-owned data accounts |
Optional Seeds
The optional seeds are user-defined byte strings that serve as inputs to the PDA derivation. They create unique, deterministic addresses scoped to a program. For example, using["user", user_pubkey] as seeds derives a different PDA for each
user.
Seeds must follow these constraints:
- Maximum 16 seeds per derivation (
MAX_SEEDS), including the bump seed, sofind_program_addresstakes at most 15 seeds of your own - Maximum 32 bytes per seed (
MAX_SEED_LEN)
Bump Seed
The bump seed is a single byte (u8) appended to the optional seeds during derivation.find_program_address
searches from 255 down to 1, calling create_program_address with each
value until the result falls off the Ed25519 curve. The first value that
succeeds is the canonical bump.
Programs should always use the canonical bump to ensure a unique, deterministic
mapping from seeds to address.
Security: Use the canonical bump onlyMost seed sets have several valid bumps, and each one derives a different
address. If your program accepts a bump from the caller, an attacker can
pass a non-canonical bump and get your program to accept a second account
for the same seeds.Find the canonical bump with
find_program_address when the account is
created, store it in the account, and verify against the stored value
afterwards. In Anchor, seeds = [...], bump finds the canonical bump on
init, and bump = account.bump checks the stored one on later
instructions. Don’t take the bump from instruction data.Derivation Algorithm
The PDA derivation is implemented in the SDK’screate_program_address
function. The algorithm works as follows:
- Validate that the number of seeds does not exceed
MAX_SEEDS(16) and no individual seed exceedsMAX_SEED_LEN(32 bytes). If either check fails, returnPubkeyError::MaxSeedLengthExceeded. - SHA-256 hash all seeds, the program ID, and the string
"ProgramDerivedAddress"together to produce a 32-byte result. - Check if the result is a valid point on the Ed25519 curve.
- If the result IS on the curve, return
PubkeyError::InvalidSeeds(the address would have a corresponding private key, which violates the PDA security property). - If the result is NOT on the curve, return it as the PDA.
Compute Unit Costs
The onchain syscall forcreate_program_address charges
1,500 CUs
per call.
The
try_find_program_address syscall
charges 1,500 CUs on entry (before the loop), then an additional 1,500 CUs for
each failed bump attempt within the loop.
Common Seed Patterns
Seeds are application-specific. Common patterns include:| Pattern | Seeds | Use case |
|---|---|---|
| Global singleton | ["global"] | Single program-wide config account |
| Per-user account | ["user", user_pubkey] | One account per user per program |
| Per-user-per-entity | ["vault", user_pubkey, mint_pubkey] | Token vaults, per-user-per-token |
| Counter / sequential | ["order", user_pubkey, &order_id.to_le_bytes()] | Sequential records per user |
Security: Prevent seed collisionsSeeds are concatenated before hashing, so
["ab", "cd"] and ["abcd"]
produce the same PDA. Use fixed-length seeds or a separator to avoid
collisions. For example, ["ab", "-", "cd"] is unambiguous. Fixed-length
values such as public keys and to_le_bytes() integers are not affected.Security: Scope signing PDAs narrowlyA PDA that signs for funds should include the user, pool, or mint it
controls in its seeds. When one global PDA (
["authority"]) is the
authority over every user’s token account, a single missing check that lets
a caller choose the destination or the account to sign for can drain all of
them. Per-entity seeds such as ["vault", user_pubkey, mint_pubkey] limit
what one signature can reach.Examples: Derive a PDA
Deriving a PDA computes an address only. It does not create an onchain account at that address. The account must be explicitly created through a separate instruction (typicallycreate_account via CPI).
The Solana SDKs provide functions for PDA derivation. Each function takes:
- Program ID: The address of the program used to derive the PDA. This program can sign on behalf of the PDA.
- Optional seeds: Predefined inputs such as strings, numbers, or other account addresses.
| SDK | Function |
|---|---|
@solana/kit (TypeScript) | getProgramDerivedAddress |
@solana/web3.js v3 (TypeScript) | PublicKey.findProgramAddress |
@solana/web3.js (legacy, TypeScript) | findProgramAddressSync |
solana_sdk (Rust) | find_program_address |
Derive a PDA with a string seed
The example below derives a PDA using a program ID and an optional string seed.The Rust tabs on this page use the 2.x Solana crates. Install the
dependencies with (tested with Rust 1.89 and 1.98):
@solana/web3.js 1.x is no longer actively maintainedIt receives critical fixes only. Use Kit for new code. To migrate existing code, follow the Kit upgrade guide, or the web3.js v3 migration guide to keep the class-based API.To run this code, install 1.x with npm install @solana/web3.js@1. A plain npm install @solana/web3.js installs v3, which this code doesn’t run on.Derive a PDA with an address seed
The example below derives a PDA using a program ID and an optional address seed.@solana/web3.js 1.x is no longer actively maintainedIt receives critical fixes only. Use Kit for new code. To migrate existing code, follow the Kit upgrade guide, or the web3.js v3 migration guide to keep the class-based API.To run this code, install 1.x with npm install @solana/web3.js@1. A plain npm install @solana/web3.js installs v3, which this code doesn’t run on.Derive a PDA with multiple seeds
The example below derives a PDA using a program ID and multiple optional seeds.@solana/web3.js 1.x is no longer actively maintainedIt receives critical fixes only. Use Kit for new code. To migrate existing code, follow the Kit upgrade guide, or the web3.js v3 migration guide to keep the class-based API.To run this code, install 1.x with npm install @solana/web3.js@1. A plain npm install @solana/web3.js installs v3, which this code doesn’t run on.Iterating All Possible Bumps
The following examples show PDA derivation using all possible bump seeds (255 to 0), illustrating howfind_program_address returns the
canonical bump:
This is distinct from the current canonical search behavior documented for
sol_try_find_program_address, which iterates from 255 down to 1.Kit example is not included because the
createProgramDerivedAddress
function isn’t exported.@solana/web3.js 1.x is no longer actively maintainedIt receives critical fixes only. Use Kit for new code. To migrate existing code, follow the Kit upgrade guide, or the web3.js v3 migration guide to keep the class-based API.To run this code, install 1.x with npm install @solana/web3.js@1. A plain npm install @solana/web3.js installs v3, which this code doesn’t run on.