Skip to main content

base58Decode

Decodes a Base58 encoded string back into its original raw byte array. This is a standalone utility function from base58.h, crucial for converting user-provided addresses or keys into the binary format required by the library.

Parameters

ParameterTypeDescription
b58const String&The input string encoded in Base58.
outputuint8_t*A pointer to the buffer where the decoded raw bytes will be stored.
outLensize_t&An input/output parameter. Initially, it must hold the capacity of the output buffer. On success, it will be updated with the actual number of decoded bytes.

Return Value

  • bool: Returns true if the decoding is successful, false otherwise (e.g., invalid Base58 characters).

Example Code (main.cpp)

#include <Arduino.h>
#include "base58.h" // Include the standalone header

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

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

String publicKeyBase58 = "So11111111111111111111111111111111111111112"; // Solana System Program ID
uint8_t decodedBuffer[32]; // A Solana public key is 32 bytes
size_t decodedLength = sizeof(decodedBuffer); // Set the capacity

Serial.println("Decoding: " + publicKeyBase58);

if (base58Decode(publicKeyBase58, decodedBuffer, decodedLength)) {
Serial.println("✅ Decoding successful!");
Serial.print(" -> Decoded length: ");
Serial.println(decodedLength);
Serial.print(" -> Decoded data (hex): ");
for (size_t i = 0; i < decodedLength; i++) {
if (decodedBuffer[i] < 16) Serial.print("0");
Serial.print(decodedBuffer[i], HEX);
}
Serial.println();
} else {
Serial.println("❌ Decoding failed. Check the input string.");
}
}

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