I I've been able to get token balances for sol and uscd plus tokens like Pyth Network using @solana.web3js. However the same code fails when retrieving the balance for ai16z.
Simplified code looks like:
import { Connection } from "@solana/web3.js";
import { getAssociatedTokenAddressSync } from "@solana/spl-token";
private usdcMint = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
private ai16zMint = new PublicKey("HeLp6NuQkmYB4pYWo2zYs22mESHXPQYzXbB8n4V98jwC");
usdcTokenAccount = getAssociatedTokenAddressSync(usdcMint, publicKey);
ai16zTokenAccount = getAssociatedTokenAddressSync(ai16zMint, wallet.publicKey);
const usdcBalanceResult = solanaConnection.getTokenAccountBalance(usdcTokenAccount)
const ai16zBalanceResult = solanaConnection.getTokenAccountBalance(ai16zTokenAccount)
usdcBalance = usdcBalanceResult.value.value.uiAmount ?? 0;
ai16zBalance = ai16zBalanceResult.value.value.uiAmount ?? 0;
The pseudo-code above works for usdc but not for ai16z. For usdc, I always get this:
usdcBalance.status = 'fulfilled'
When for ai16z, I always get
ai16zBalanceResult.status = 'rejected'
With this error:
"failed to get token account balance: Invalid param: could not find account"
HeLp6NuQkmYB4pYWo2zYs22mESHXPQYzXbB8n4V98jwC is the correct account for ai16z. ai16z: https://solscan.io/token/HeLp6NuQkmYB4pYWo2zYs22mESHXPQYzXbB8n4V98jwC usdc: https://solscan.io/token/EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v