How to Get Account Balance
get-account-balance.ts
import { address, createSolanaRpc } from "@solana/web3.js";
const rpc = createSolanaRpc("https://api.devnet.solana.com");
const LAMPORTS_PER_SOL = 1_000_000_000; // 1 billion lamports per SOL
const wallet = address("nicktrLHhYzLmoVbuZQzHUTicd2sfP571orwo9jfc8c");
const { value: balance } = await rpc.getBalance(wallet).send();
console.log(`Balance: ${Number(balance) / LAMPORTS_PER_SOL} SOL`);
Info
As of v2.0.0
, developers can use the default configurations within the main
library (@solana/web3.js
) or import any of its subpackages where better
composition or more granular control over the imports is desired. See
Tree-Shakability
for more information.