UNPKG

solana-web3-lite

Version:

A lightweight wrapper around @solana/web3.js for simplified Solana blockchain interactions

34 lines (33 loc) 1.8 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.showBalance = void 0; const utils_1 = require("./utils"); const helpers_1 = require("@solana-developers/helpers"); const showBalance = (_a) => __awaiter(void 0, [_a], void 0, function* ({ address, cluster = "devnet", commitment = "confirmed", }) { try { console.log(`Fetching balance on ${cluster}...`); if (!address) throw new Error("Public key string is required."); const pubKey = (0, utils_1.toPublicKey)(address); const connection = (0, utils_1.getConnection)({ cluster, commitment }); const balanceInLamports = yield connection.getBalance(pubKey); const balanceInSol = (0, utils_1.lamportsToSol)(balanceInLamports); const explorerLink = (0, helpers_1.getExplorerLink)("address", pubKey.toBase58(), cluster); console.log(`✅ Visit Explorer for more info: ${explorerLink}`); return balanceInSol; } catch (error) { console.error("Failed to fetch balance:", error); throw error; } }); exports.showBalance = showBalance;