Skip to main content

derivePDA

Derives a Program Derived Address (PDA). A PDA is a special address that is deterministically derived from a program ID and a set of "seeds," but which has no corresponding private key. This allows programs to sign for certain accounts themselves.

This is a user-friendly wrapper around findProgramAddress that works with Base58 strings.

Parameters

ParameterTypeDescription
seedsconst std::vector<std::vector<uint8_t>>&A vector of seeds used to derive the PDA. Each seed is a byte vector (e.g., from a string or public key).
programIdBase58const String&The Base58 address of the program the PDA is derived from.
outPDABase58String&An output parameter that will be populated with the Base58 string of the derived PDA.
outBumpuint8_t&An output parameter that will be populated with the 8-bit 'bump' seed (nonce) used to push the address off the elliptic curve.

Return Value

  • bool: Returns true if a valid PDA was found, false otherwise.

Example Code (main.cpp)

#include <Arduino.h>
#include "Infratic-lib.h"

// --- Settings ---
const String SOLANA_RPC_URL = "[https://api.devnet.solana.com](https://api.devnet.solana.com)";
const String MY_PUBLIC_KEY_BASE58 = "YOUR_PUBLIC_KEY_BASE58"; // Use your public key
const String PROGRAM_ID_BASE58 = "MemoSq4gqABAXKb96qnH8TysNcVtrp5GzAufjCUajQN"; // Using Memo Program as an example

Infratic solana(SOLANA_RPC_URL);

void setup() {
Serial.begin(115200);
delay(1000);

Serial.println("\n=== Derive PDA Example ===");

// Construct the seeds for derivation
// Seed 1: The string "pda_account"
// Seed 2: The user's public key
std::string seed1_str = "pda_account";
std::vector<uint8_t> seed1(seed1_str.begin(), seed1_str.end());
std::vector<uint8_t> seed2 = base58ToPubkey(MY_PUBLIC_KEY_BASE58);

std::vector<std::vector<uint8_t>> seeds = { seed1, seed2 };

String pdaAddress;
uint8_t bump;

if (solana.derivePDA(seeds, PROGRAM_ID_BASE58, pdaAddress, bump)) {
Serial.println("✅ PDA derived successfully!");
Serial.println(" -> PDA Address: " + pdaAddress);
Serial.print(" -> Bump Seed: ");
Serial.println(bump);
} else {
Serial.println("❌ Failed to derive PDA.");
}
}

void loop() {
// Can be left empty
}