admin管理员组文章数量:1278789
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: usdc:
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
Share Improve this question edited Feb 24 at 18:50 Biosopher asked Feb 24 at 3:58 BiosopherBiosopher 6166 silver badges14 bronze badges1 Answer
Reset to default 0I found my answer here: https://solana.stackexchange/questions/8549/how-to-getprogramaccounts-for-token-2022-program
Plus this helped with a more simplified set of code to follow: https://www.quicknode/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.
本文标签: Cannot access spltoken account balance for ai16z using solanaweb3jsStack Overflow
版权声明:本文标题:Cannot access spl-token account balance for ai16z using @solana.web3js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741294979a2370765.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论