getEpochInfo
Queries the Solana cluster for information about the current epoch. An epoch is a period of time on the network defined by a certain number of slots. This function provides detailed data about the network's current state and timing.
The EpochInfo Structure
The function populates a pointer to the following C++ structure:
Parameters
| Parameter | Type | Description |
|---|---|---|
outEpochInfo | EpochInfo& | An output parameter. This is a reference to an EpochInfo struct that will be populated with the current epoch data upon successful execution. |
Return Value
bool: Returns true if the epoch information was fetched successfully, false otherwise.
Example Code (main.cpp)
#include <Arduino.h>
#include <WiFi.h>
#include "Infratic-lib.h"
// --- WiFi Settings ---
const char* WIFI_SSID = "YOUR_WIFI_SSID";
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";
// --- Solana Settings ---
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);
// Connect to WiFi
Serial.print("Connecting to WiFi...");
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\n✅ WiFi connected!");
Serial.println("\n=== Get Epoch Info Example ===");
EpochInfo currentEpoch;
if (solana.getEpochInfo(currentEpoch)) {
Serial.println("✅ Epoch Info Received Successfully:");
Serial.printf(" -> Absolute Slot: %llu\n", currentEpoch.absoluteSlot);
Serial.printf(" -> Block Height : %llu\n", currentEpoch.blockHeight);
Serial.printf(" -> Epoch : %llu\n", currentEpoch.epoch);
Serial.printf(" -> Slot Index : %llu\n", currentEpoch.slotIndex);
Serial.printf(" -> Slots/Epoch : %llu\n", currentEpoch.slotsInEpoch);
} else {
Serial.println("❌ Failed to get epoch info.");
}
}
void loop() {
// This example runs once in setup.
}