DeveloperBreeze

Fetch Balance Development Tutorials, Guides & Insights

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

Fetching Address Details from Solana

Tutorial August 09, 2024
javascript json

Next, let's fetch the balance of a specific wallet address. Add the following function to your index.js file:

async function getWalletBalance(walletAddress) {
  try {
    const publicKey = new solanaWeb3.PublicKey(walletAddress);
    const balance = await connection.getBalance(publicKey);
    console.log(`Wallet Balance: ${balance / solanaWeb3.LAMPORTS_PER_SOL} SOL`);
  } catch (error) {
    console.error('Error fetching wallet balance:', error);
  }
}

// Replace with your Solana wallet address
const walletAddress = 'YourWalletAddressHere';
getWalletBalance(walletAddress);