PDA Derivation - Automatic Program Derived Address Calculation
Overview
Section titled “Overview”Program Derived Addresses (PDAs) are a fundamental concept in Solana programming, but calculating them manually during testing can be tedious and error-prone. Testship automatically derives PDAs for you, handling both simple and complex derivation patterns.
What are PDAs?
Section titled “What are PDAs?”PDAs are deterministic addresses derived from:
- A program ID
- One or more seeds (strings, public keys, or other data)
- A bump seed (to ensure the address is off the ed25519 curve)
Automatic Derivation
Section titled “Automatic Derivation”Basic PDAs
Section titled “Basic PDAs”For simple PDA patterns like:
#[account( seeds = [b"user", authority.key().as_ref()], bump)]
Testship automatically:
- Identifies the seeds from your program’s IDL
- Creates appropriate input fields for variable seeds
- Calculates the PDA when you provide the required inputs
- Displays the derived address
Complex PDAs
Section titled “Complex PDAs”Testship handles advanced patterns including:
Multiple Seeds
seeds = [b"vault", token_mint.key().as_ref(), owner.key().as_ref()]
Numeric Seeds
seeds = [b"order", order_id.to_le_bytes().as_ref()]
Nested PDAs
// Uses another PDA as a seedseeds = [b"derived", pda_account.key().as_ref()]
Features
Section titled “Features”Visual PDA Builder
Section titled “Visual PDA Builder”The PDA Builder interface shows:
- All required seeds in order
- Input fields for variable seeds
- Constant seeds (auto-filled)
- The derived address (live-updated)
- The bump seed used
Seed Validation
Section titled “Seed Validation”Testship validates:
- Seed type compatibility
- Required vs optional seeds
- Seed length constraints
- Format requirements (e.g., proper byte conversion)
PDA History
Section titled “PDA History”Previously derived PDAs are saved:
- Quick access to frequently used addresses
- Reuse across different instructions
- Share with team members via session links
Bump Seed Handling
Section titled “Bump Seed Handling”Testship automatically:
- Finds the canonical bump seed
- Caches bump values for performance
- Handles manual bump specification when needed
Example Usage
Section titled “Example Usage”Deriving a User Account PDA
Section titled “Deriving a User Account PDA”- Navigate to an instruction requiring a user PDA
- Fill in the authority (wallet) address
- Testship automatically derives:
[b"user", authority_pubkey]
- The derived PDA appears in the account field
Multi-Step Derivations
Section titled “Multi-Step Derivations”For instructions with multiple PDAs:
- Derive the first PDA (e.g., vault account)
- Use that PDA to derive the next (e.g., vault authority)
- Both addresses auto-populate in the instruction form
Benefits
Section titled “Benefits”- No Manual Calculation: Never compute PDAs by hand
- Error Prevention: Avoid typos and calculation mistakes
- Speed: Instantly derive complex addresses
- Learning Tool: Understand PDA patterns in your program
- Consistency: Same derivation logic as your on-chain program
Advanced Options
Section titled “Advanced Options”Custom Seed Providers
Section titled “Custom Seed Providers”For non-standard seed patterns:
- Upload seed data from files
- Use computed values from previous transactions
- Integrate external data sources
Bump Override
Section titled “Bump Override”When you need a specific bump:
- Manually specify the bump seed
- Useful for debugging and edge cases
- Warning displayed if non-canonical bump used
Next Steps
Section titled “Next Steps”Learn how Testship remembers your frequently used accounts in Account Suggestions.