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
| Parameter | Type | Description |
|---|---|---|
b58 | const String& | The input string encoded in Base58. |
output | uint8_t* | A pointer to the buffer where the decoded raw bytes will be stored. |
outLen | size_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: Returnstrueif the decoding is successful,falseotherwise (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
}