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);
Parameters
programAddress
:Address
- The program address to derive the PDA fromseeds
:Array<String | Address | BigInt>
- 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)
Returns
Returns a Promise<{pda: Address, bump: number}>
containing:
pda
: The derived program addressbump
: 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
];
const { pda, bump } = await connection.getPDAAndBump(programAddress, seeds);
console.log("PDA:", pda.toString());
console.log("Bump seed:", bump);
Understanding PDAs
Program Derived Addresses (PDAs) are special addresses that are:
- Derived deterministically from a set of seeds and a program address
- Guaranteed to not have a corresponding private key
- 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