findAssociatedTokenAccount
Finds the Associated Token Account (ATA) address for a given wallet (owner) and a given SPL Token mint. The ATA is the standard, deterministic address where a user holds tokens of a specific type. This function calculates the address locally without needing an on-chain query.
The ATA is required when you want to send or receive SPL tokens from a user.
Parameters
| Parameter | Type | Description |
|---|---|---|
ownerPubkeyBase58 | const String& | The Base58 address of the wallet that owns the token account. |
mintPubkeyBase58 | const String& | The Base58 address of the SPL Token's mint. |
outATA | String& | An output parameter that will be populated with the Base58 address of the calculated ATA. |
Return Value
bool: Returnstrueif the ATA was calculated successfully,falseotherwise.
Example Code (main.cpp)
#include <Arduino.h>
#include "Infratic-lib.h"
// --- Settings ---
const String SOLANA_RPC_URL = "[https://api.devnet.solana.com](https://api.devnet.solana.com)";
// Your wallet address or a test wallet
const String OWNER_PUBLIC_KEY_BASE58 = "YOUR_PUBLIC_KEY_BASE58";
// Example: Devnet USDC mint address
const String TOKEN_MINT_BASE58 = "Gh9ZwEmdLJ8DscKNTkTqPbNwLNNBjuSzaG9Vp2KGtKJr";
Infratic solana(SOLANA_RPC_URL);
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("\n=== Find Associated Token Account Example ===");
String ataAddress;
if (solana.findAssociatedTokenAccount(OWNER_PUBLIC_KEY_BASE58, TOKEN_MINT_BASE58, ataAddress)) {
Serial.println("✅ ATA found successfully!");
Serial.println(" -> Owner: " + OWNER_PUBLIC_KEY_BASE58);
Serial.println(" -> Token Mint: " + TOKEN_MINT_BASE58);
Serial.println(" -> ATA Address: " + ataAddress);
} else {
Serial.println("❌ Failed to find ATA. Check input addresses.");
}
}
void loop() {
// Can be left empty
}