Skip to main content

getBlockHeight

Queries the current block height of the Solana cluster. The block height represents the number of blocks that have been produced since the genesis block.

Parameters

ParameterTypeDescription
outBlockHeightuint64_t&An output parameter. If the query is successful, this 64-bit unsigned integer will be populated with the current block height.

Return Value

  • bool: Returns true if the block height was fetched successfully, false on failure (e.g., network error).

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 Block Height Example ===");

uint64_t blockHeight = 0;
if (solana.getBlockHeight(blockHeight)) {
Serial.print("✅ Current Block Height: ");
Serial.println((unsigned long)blockHeight);
} else {
Serial.println("❌ Failed to get block height.");
}
}

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