Get Sol Balance

import { Connection, Keypair, LAMPORTS_PER_SOL } from "@solana/web3.js";
import * as bs58 from "bs58";

// connection
const connection = new Connection("https://api.devnet.solana.com");

// 5YNmS1R9nNSCDzb5a7mMJ1dwK9uHeAAF4CmPEwKgVWr8
const feePayer = Keypair.fromSecretKey(
  bs58.decode("588FU4PktJWfGfxtzpAAXywSNt74AvtroVzGfKkVN1LwRuvHwKGr851uH8czM5qm4iqLbs1kKoMKtMJG4ATR7Ld2")
);

(async () => {
  let balance = await connection.getBalance(feePayer.publicKey);
  console.log(`${balance / LAMPORTS_PER_SOL} SOL`);
})();












 
 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Last Updated: 9/23/2022, 6:56:02 PM
Contributors: Yihau Chen