DeveloperBreeze

Token Holdings Development Tutorials, Guides & Insights

Unlock 1+ expert-curated token holdings tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your token holdings skills on DeveloperBreeze.

Fetching Address Details from Solana

Tutorial August 09, 2024
javascript json

async function getTokenHoldings(walletAddress) {
  try {
    const publicKey = new solanaWeb3.PublicKey(walletAddress);
    const tokenAccounts = await connection.getParsedTokenAccountsByOwner(publicKey, {
      programId: solanaWeb3.TOKEN_PROGRAM_ID,
    });

    console.log('Token Holdings:');
    tokenAccounts.value.forEach((tokenAccount) => {
      const tokenAmount = tokenAccount.account.data.parsed.info.tokenAmount.uiAmount;
      const tokenMint = tokenAccount.account.data.parsed.info.mint;
      console.log(`- Token Mint: ${tokenMint}`);
      console.log(`  Amount: ${tokenAmount}`);
    });
  } catch (error) {
    console.error('Error fetching token holdings:', error);
  }
}

getTokenHoldings(walletAddress);

This function uses the getParsedTokenAccountsByOwner method to retrieve token accounts owned by the wallet address. It then logs the token mint address and the amount held.