Skip to main content

findProgramAddress

This is the low-level version of derivePDA. It finds a Program Derived Address (PDA) and its corresponding "bump" seed using raw byte vectors (std::vector<uint8_t>) instead of Base58 strings.

This is typically used internally by the library or when you need to work with addresses in their raw byte format.

Parameters

ParameterTypeDescription
seedsconst std::vector<std::vector<uint8_t>>&A vector of byte vectors to be used as seeds for the derivation.
programIdconst std::vector<uint8_t>&The 32-byte raw address of the program.
outPDAstd::vector<uint8_t>&An output parameter that will be populated with the calculated 32-byte PDA.
outBumpuint8_t&An output parameter that will be populated with the calculated 'bump' seed.

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";
const String PROGRAM_ID_BASE58 = "MemoSq4gqABAXKb96qnH8TysNcVtrp5GzAufjCUajQN";

Infratic solana(SOLANA_RPC_URL);

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

Serial.println("\n=== findProgramAddress Example ===");

// Convert inputs to raw byte format
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 };

std::vector<uint8_t> programId = base58ToPubkey(PROGRAM_ID_BASE58);

std::vector<uint8_t> pda_bytes;
uint8_t bump;

if (solana.findProgramAddress(seeds, programId, pda_bytes, bump)) {
Serial.println("✅ PDA found successfully!");
Serial.print(" -> PDA (hex): ");
for (uint8_t b : pda_bytes) {
if (b < 16) Serial.print("0");
Serial.print(b, HEX);
}
Serial.println();
Serial.print(" -> Bump Seed: ");
Serial.println(bump);
} else {
Serial.println("❌ Failed to find PDA.");
}
}

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