Skip to main content

base64Encode

This utility function encodes raw byte data into a Base64 encoded string. This is primarily used for serializing a transaction to send to a Solana RPC API, as the sendTransaction endpoint expects the transaction data to be Base64 encoded.

Parameters

ParameterTypeDescription
dataconst uint8_t*A pointer to the start of the byte array to be encoded.
lensize_tThe length of the data in bytes.

Return Value

  • String: The Base64 encoded representation of the data.

Example Code (main.cpp)

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

// Network connection is not required for this function.
const String SOLANA_RPC_URL = "[https://api.devnet.solana.com](https://api.devnet.solana.com)";
Infratic solana(SOLANA_RPC_URL);

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

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

const char* originalData = "Testing with the Infratic Library!";
String encoded = solana.base64Encode((const uint8_t*)originalData, strlen(originalData));

Serial.println("✅ Original Data: " + String(originalData));
Serial.println("✅ Base64 Encoded: " + encoded);

// Expected output: "VGVzdGluZyB3aXRoIHRoZSBJbmZyYXRpYyBMaWJyYXJ5IQ=="
}

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