Introducing a new way to review your PRs.

Read the announcement

solana-foundation / program-examples

A repository of Solana program examples

View on GitHub

19 documents · Updated Nov 23, 2026

docs / program-derived-address-design

Program-derived address design

Program-derived addresses (PDAs) give a Solana program stable addresses for state and program-controlled funds. The basic examples derive each address from the program ID and a small seed set, carry the selected bump when needed, and use the result as an account and authority contract. The current page-visit example shows the same design in both Anchor and native program forms. See Solana programming basics for the wider account model, account lifecycles for creation and closure, and instruction and CPI patterns for signer use across program calls.

Deterministic address derivation

A PDA is an address that a program can reproduce from its program ID and ordered seed bytes. The same inputs always identify the same address, so a client can find program state before it has received an address from the program. The program ID is part of this identity, which keeps the same seed set separate across programs.

Seed contracts

Seeds are the naming contract for a PDA. The page-visit examples use the readable prefix page_visits, then add the payer or user public key that defines the record's scope. The favorites example follows the same pattern with favorites and the user's key. The seed order and byte form are part of the address, not a display choice.

Good seed sets make the state relationship clear:

  • Use a fixed prefix to separate one kind of account from another.
  • Add the key that gives the account its scope, such as a user or parent account.
  • Keep the order and encoding stable across clients and program instructions.

References: basics/…/page_visits.rs• L3-12 basics/…/create.rs• L4-20 basics/…/page_visits.rs• L7-18 basics/…/lib.rs• L50-66

Bump values

The derivation process searches for a one-byte bump that produces a valid PDA for the chosen seed set. The bump is not a second identity for the account. It is the value that completes the seed contract and lets the program reproduce the same address during a later signed action.

The page-visit examples store the bump with the account state. Anchor obtains it during account creation and stores it with the initial record. The native create path receives the record, including its bump, and uses that value for the signed account-creation call. A client derives the address and bump together when the instruction format requires it.

References: basics/…/page_visits.rs• L5-15 basics/…/create.rs• L9-25 basics/…/page_visits.rs• L7-18 basics/…/create.rs• L18-31

PDA authority model

A PDA has no private key. The program that owns the seed contract can ask the runtime to accept the PDA as a signer by supplying the same seeds and bump during a signed invocation. This separates a transaction user's authority from a program's authority.

User and program authorities

The user signs the transaction when the user must approve payment or a state change. The PDA signs only when the program must act for program-controlled funds or another PDA-owned role. An address alone does not prove either form of authority.

The rent-vault example shows this split. A caller supplies a new account, then the program uses the vault's seeds and bump to move lamports through a System Program account-creation call. The vault can therefore pay for an account without a private key. This basic example does not check caller authority, so any caller can request spending from the vault; it demonstrates PDA signing rather than a complete access policy.

This diagram shows the two authority paths in one account flow.

sequenceDiagram
    participant User
    participant Program
    participant Vault as Rent-vault PDA
    participant System as System Program
    User->>Program: Approve instruction and provide payer
    Program->>Vault: Validate rent-vault seeds
    Program->>System: Create account with PDA signer seeds
    Vault-->>System: Authorize the lamport source

References: basics/…/init_rent_vault.rs• L4-30 basics/…/create_new_account.rs• L4-40 basics/…/init_rent_vault.rs• L18-42

Signed PDA calls

PDA signing is valid only for the exact seed set and program ID that produced the address. The program passes those seeds to the CPI boundary when it asks another program to create an account or move funds. Anchor expresses this through a signer context, while native and low-level examples build the signer seed set directly.

The called program still applies its own account and authority rules. PDA seeds provide the program-level signature proof; they do not replace checks for the target account, owner, payer, or requested operation.

The native page-visit example uses the PDA signer path to let the payer-funded transaction create an account owned by the program. The PDA is the address being created, not a user wallet that signs the transaction.

References: basics/…/create_new_account.rs• L20-40 basics/…/create.rs• L11-31 basics/…/create.rs• L9-20

Address-driven state

Address-driven state uses a PDA as the canonical location for a relationship or record. The instruction does not need a separate account registry: it derives the expected address from the relationship and reads or updates the account at that address.

User-scoped records

The page-visit example creates one PageVisits account for each user from page_visits and the user's public key. The record starts at zero and later increments use the same derived address. The Anchor example validates that relationship through its account seeds and the stored bump. The native example creates the account with the same seed set and then updates the supplied account. The favorites example applies the same pattern to one favorites record per user.

The client and program meet at the PDA contract:

  1. The client derives the address from the program ID and seed values.
  2. The create instruction initializes that address and records the initial state.
  3. A later instruction supplies the same address and changes only its stored value.
  4. A read derives or receives the address and decodes the record found there.

References: basics/…/create.rs• L4-26 basics/…/increment.rs• L4-21 basics/…/test_program_derived_addresses.rs• L38-69 basics/…/create.rs• L11-31 basics/…/increment.rs• L9-16 basics/…/test.ts• L30-69

Account validation

Every instruction should connect the supplied account to the expected seed relationship. Anchor places the seed contract in account constraints, so the page-visit increment path checks the user-derived address and the stored bump before it changes state. A native program must provide the equivalent address check when it accepts an account from a caller; the current native increment example focuses on decoding and updating the supplied record after creation.

The three basic program styles express the same design in different ways. Anchor places the seed contract in account constraints. Native code can derive the expected PDA and compare it with the supplied account. Pinocchio can recreate the address from the supplied bump and reject an invalid seed result. The important contract is the address relationship rather than the framework syntax.

References: basics/…/increment.rs• L4-15 basics/…/lib.rs• L50-66 basics/…/create_pda.rs• L14-26 basics/…/get_pda.rs• L11-25 basics/…/increment.rs• L9-16

PDA design patterns

The basic examples use two related PDA patterns. One stores application state at an address derived from a user. The other uses a program-controlled PDA as a stable source of lamports for later account work.

PatternAddress inputsMain purpose
User-scoped stateFixed prefix plus user public keyFind one record for each user without a registry.
Program-controlled vaultFixed prefix plus program IDHold funds at a known address and authorize program actions.

These patterns can be combined. A larger state model can derive child accounts from a parent PDA and additional identifiers. Each added seed must express a real uniqueness rule and remain stable for the life of the account.

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the seed prefix, seed order, byte encoding, and program ID identical in clients, account constraints, address checks, and signer seed sets.
  • Keep bump transport and storage aligned with the instruction data and account state. A missing or changed bump can make an existing PDA unusable for later signed calls.
  • Review every account that uses a changed seed contract. A new seed can change the address and leave old state outside the program's normal lookup path.
  • Preserve the distinction between the transaction payer's signature and a PDA's program signature when a CPI account or funding path changes.
  • Keep the relationship key used for derivation tied to the authority check. A user-scoped PDA must not be accepted for a different user.

Important failure modes

TriggerConsequenceGuard
Client and program use different seed order or encodingThe client supplies an address that the program cannot validate or findDefine one seed contract and use it at every derivation boundary
A create or CPI call uses the wrong bumpPDA creation or runtime signer verification failsDerive the bump with the address and pass the matching value to the program action
An instruction accepts a PDA without checking its user or parent relationshipThe caller may read or change unrelated stateDerive or constrain the expected PDA from the instruction's relationship key
A program treats a PDA as a normal transaction signerThe action lacks a valid signature or cannot authorize a CPIUse the PDA seed set with a signed invocation when the program must act for the PDA
A vault-funding instruction omits a caller authority checkAny caller may spend lamports held by the vaultRequire an authorized signer or stored authority before using the vault as a funding source
A seed contract changes after accounts are deployedExisting accounts are no longer found at the expected addressesTreat seed prefixes, order, and scope keys as stable account schema

Key files

FileWhy to read it
basics/…/page_visits.rsDefines the user-scoped state shape, seed prefix, and stored bump.
basics/…/create.rsShows the PDA creation contract and initial state setup.
basics/…/increment.rsShows later state access through the same user-derived PDA.
basics/…/test_program_derived_addresses.rsShows client-side address derivation and the create-then-increment state flow in a local program test.
basics/…/create.rsShows native account creation with the page-visit seed set and PDA signer seeds.
basics/…/increment.rsShows native state updates after the PDA account exists.
basics/…/page_visits.rsDefines the native record, seed prefix, stored bump, and increment behavior.
basics/…/lib.rsShows a user-scoped PDA that stores an application record and can be initialized on first use.
basics/…/create_pda.rsShows explicit PDA comparison before account creation.
basics/…/get_pda.rsShows PDA validation before reading address-driven state.
basics/…/create_new_account.rsShows a PDA authorizing a System Program call to fund new account creation and notes the need for caller authorization.
basics/…/init_rent_vault.rsShows the stable rent-vault address and its bump during setup.