Skip to Content

Get PDA and Bump

The getPDAAndBump function gets a Program Derived Address (PDA) and its bump seed from a program address and seeds. It automatically handles encoding of different seed types.

Usage

const { pda, bump } = await connection.getPDAAndBump(programAddress, seeds); // or with big-endian encoding for BigInt seeds const { pda, bump } = await connection.getPDAAndBump(programAddress, seeds, true);

Parameters

  • programAddress: Address - The program address to derive the PDA from
  • seeds: Array<String | Address | BigInt | Uint8Array> - Array of seeds to derive the PDA. Can include:
    • Strings (encoded as UTF-8)
    • Addresses (encoded as base58)
    • BigInts (encoded as 8-byte little-endian by default, or big-endian if useBigEndian is true)
    • Uint8Array (used as-is)
  • useBigEndian: boolean (optional) - Whether to use big-endian byte order for BigInt seeds (default: false)

Returns

Returns a Promise<{pda: Address, bump: number}> containing:

  • pda: The derived program address
  • bump: The bump seed used to derive the address

Example

const programAddress = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address; const seeds = [ "offer", // string seed aliceAddress, // address seed 420n, // bigint seed ]; // Default: little-endian encoding for BigInt seeds const { pda, bump } = await connection.getPDAAndBump(programAddress, seeds); console.log("PDA:", pda.toString()); console.log("Bump seed:", bump); // Using big-endian encoding for BigInt seeds const { pda: pdaBigEndian, bump: bumpBigEndian } = await connection.getPDAAndBump(programAddress, seeds, true); console.log("PDA (big-endian):", pdaBigEndian.toString()); console.log("Bump seed (big-endian):", bumpBigEndian); // Using Uint8Array seeds const customSeed = new Uint8Array([1, 2, 3, 4]); const seedsWithUint8Array = ["custom", customSeed, 123n]; const { pda: pdaCustom, bump: bumpCustom } = await connection.getPDAAndBump(programAddress, seedsWithUint8Array);

Understanding PDAs

Program Derived Addresses (PDAs) are special addresses that are:

  1. Derived deterministically from a set of seeds and a program address
  2. Guaranteed to not have a corresponding private key
  3. Can only be signed for by their owning program

Common uses for PDAs include:

  • Creating deterministic addresses for program accounts
  • Cross-Program Invocation (CPI) signing
  • Organizing program data with predictable addresses
Last updated on