getTokenDecimals
Queries a SPL Token's mint address to get its number of decimal places (decimals). SPL Token balances are stored as integers on-chain, and the decimals value is needed to convert the raw balance into a user-friendly, readable format. For example, a token with 6 decimals represents 1 token as the integer 1,000,000.
Parameters
| Parameter | Type | Description |
|---|---|---|
mintPubkeyBase58 | const String& | The Base58 address of the SPL Token mint. |
outDecimals | uint8_t& | An output parameter that will be populated with the number of decimals. |
Return Value
bool: Returnstrueif the decimal information was fetched successfully,falseotherwise.
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)";
// Example: Devnet USDC mint address (has 6 decimals)
const String TOKEN_MINT_BASE58 = "Gh9ZwEmdLJ8DscKNTkTqPbNwLNNBjuSzaG9Vp2KGtKJr";
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 Token Decimals Example ===");
uint8_t decimals = 0;
if (solana.getTokenDecimals(TOKEN_MINT_BASE58, decimals)) {
Serial.print("✅ The token with mint '");
Serial.print(TOKEN_MINT_BASE58);
Serial.print("' has ");
Serial.print(decimals);
Serial.println(" decimals.");
} else {
Serial.println("❌ Failed to get token decimals.");
}
}
void loop() {
// Can be left empty
}