Skip to main content

base58ToPubkey

This utility function converts a Base58 encoded string (typically a public key or address) into a 32-byte std::vector<uint8_t> (byte vector). In Solana, addresses are commonly represented in Base58, but they need to be in their raw byte format for on-chain operations and cryptographic functions.

Parameters

ParameterTypeDescription
base58Strconst String&The Base58 encoded string to be converted.

Return Value

  • std::vector<uint8_t>: If successful, returns a byte vector containing the 32 bytes of the public key. Returns an empty vector on failure.

Example Code (main.cpp)

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

// This is a global utility function within the library.

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

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

const String publicKeyBase58 = "So11111111111111111111111111111111111111112"; // Solana System Program ID
std::vector<uint8_t> pubkeyVec = base58ToPubkey(publicKeyBase58);

if (pubkeyVec.size() == 32) {
Serial.print("✅ Successfully converted. Public Key (hex): ");
for (uint8_t b : pubkeyVec) {
if (b < 16) Serial.print("0");
Serial.print(b, HEX);
}
Serial.println();
} else {
Serial.println("❌ Public key conversion failed!");
}
}

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