• Retrieves the SOL balance in lamports for a given Solana public key.

    Parameters

    • endpoint: string

      The Solana network endpoint to connect to.

    • pubkey: string

      The public key of the account whose balance is to be fetched.

    Returns Promise<number>

    • A promise that resolves with the number of lamports in the account.

    Throws

    • Throws an error if unable to fetch the account information.

    Example

    const run = async () => {
    const solanaEndpoint = 'https://api.mainnet-beta.solana.com';
    const publicKey = 'YourPublicKeyHere';

    try {
    const balance = await getSolBalance(solanaEndpoint, publicKey);
    console.log(`Balance in lamports: ${balance}`);
    } catch (error) {
    console.error('Error:', error);
    }
    }

    run();

Generated using TypeDoc