Reputation: 1
I am currently creating a web3 staking app for a solona blockchain token in reactjs. how can I get balance of a specific token? I can only get the balance or sol balance of the wallet not the specific token.
list of tokens inside the login wallet with its current balance
const getBalance = async () => {
const newBalance = await connection.getBalance(publicKey);
const elsaMintAddress = new PublicKey("Haj7CedKUSb44fHfcddypYFac33bKqBkNgtBFaTkpump");
const tokenAccounts = await connection.getParsedTokenAccountsByOwner(publicKey, {
programId: new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"),
});
const elsaAccount = tokenAccounts.value.find(
(account) =>
account.account.data.parsed.info.mint === elsaMintAddress.toString()
);
return {
newBalance,
elsaAccount
}
}
elsaAccount is always undefined
Upvotes: 0
Views: 86