could someone help me with this:?
I've been trying to get the amount of tokens of a connected wallet from a TokenAccount.
Right Below you can see that I successfully retrieved the TokenAccount address and the spl tokens supply but I don't know what's next...
I want to get only the amount of SPL TOKENS from the wallet connected to my DAPP. Ty and have a good day.
// Check for Solana & Phantom
var provider = () => {
if ("solana" in window) {
var provider = window.solana;
if (provider.isPhantom) {
return provider;
} else {
return false;
}
}
window.open("https://phantom.app", "_blank");
};
var phantom = provider();
if (phantom !== false) {
console.log("Phantom Wallet Found, Connecting..");
try {
// Connect to Solana
var connect_wallet = phantom.connect();
// After Connecting
phantom.on("connect", () => {
conn.addEventListener('click', () => {
user_balance.classList.toggle('expand');
})
// Check Connection
console.log("Phantom Connected: " + phantom.isConnected);
// Get Wallet Address
const wallet = phantom.publicKey;
var wallet_address = phantom.publicKey.toString();
console.log("Solana Wallet Address: " + wallet_address);
var first = wallet_address.substring(0, 5);
document.getElementById('wallet-address').innerHTML = first + '...';
(async () => {
const connection = new solanaWeb3.Connection(solanaWeb3.clusterApiUrl("mainnet-beta"),
'confirmed',
);
if (phantom && phantom.publicKey !== null) {
const tokenAccount = new solanaWeb3.PublicKey(
"J3Lw33iBvMLHdCua4MXohTx3HD4JcajQmogQEr2Y7pej"
);
let tokenAmount = await connection.getTokenAccountBalance(tokenAccount);
console.log(`amount: ${tokenAmount.value.amount}`);
const balance = await connection.getBalance(phantom.publicKey);
console.log(balance / 1000000000);
}
})();