getSolBalance
Queries the native SOL balance of a specified wallet address. The balance is returned in lamports, which is the smallest unit of SOL.
The conversion is: 1 SOL = 1,000,000,000 lamports.
Parameters
| Parameter | Type | Description |
|---|---|---|
walletPubkeyBase58 | const String& | The Base58-encoded public key of the wallet to query. |
outLamports | uint64_t& | An output parameter. This is a reference to a uint64_t variable that will be populated with the wallet's balance in lamports. |
Return Value
bool: Returnstrueif the balance was fetched successfully,falseon failure.
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)";
// Enter the public key you want to check the balance of.
const String MY_PUBLIC_KEY_BASE58 = "YOUR_PUBLIC_KEY_BASE58";
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 SOL Balance Example ===");
Serial.println("Querying balance for: " + MY_PUBLIC_KEY_BASE58);
uint64_t lamports = 0;
if (solana.getSolBalance(MY_PUBLIC_KEY_BASE58, lamports)) {
Serial.print("✅ Balance successfully retrieved!\n");
Serial.print(" -> Lamports: ");
Serial.println((unsigned long)lamports);
Serial.print(" -> SOL: ");
Serial.println((double)lamports / 1000000000.0, 9); // 1 Billion lamports = 1 SOL
} else {
Serial.println("❌ Failed to get SOL balance. Check the public key and network connection.");
}
}
void loop() {
// This example runs once in setup.
}