0

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

1 Answer 1

0

I found my answer here: https://solana.stackexchange.com/questions/8549/how-to-getprogramaccounts-for-token-2022-program

Plus this helped with a more simplified set of code to follow: https://www.quicknode.com/guides/solana-development/spl-tokens/how-to-get-all-tokens-held-by-a-wallet-in-solana

Turns out that ai16z tokens are part of the 2022 token program so must be looked up in a different manner.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.