UNPKG

nodana

Version:
47 lines 2.15 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.WalletClient = void 0; const web3_js_1 = require("@solana/web3.js"); class WalletClient { constructor(config) { this.config = config; } fetchBalance(wallet) { return __awaiter(this, void 0, void 0, function* () { try { const connection = new web3_js_1.Connection((0, web3_js_1.clusterApiUrl)(this.config.network), "confirmed"); const balance = yield connection.getBalance(new web3_js_1.PublicKey(wallet)); return balance / web3_js_1.LAMPORTS_PER_SOL; } catch (error) { throw error; } }); } requestAirDrop(wallet, sol) { return __awaiter(this, void 0, void 0, function* () { try { const connection = new web3_js_1.Connection((0, web3_js_1.clusterApiUrl)(this.config.network), "confirmed"); const txhash = yield connection.requestAirdrop(new web3_js_1.PublicKey(wallet), sol * web3_js_1.LAMPORTS_PER_SOL); if (sol > 1) { return "Not allowed to airdrop more than 1 SOL"; } return `Airdropped ${sol} successfully ✅ | txhash: ${txhash}`; } catch (error) { throw error; } }); } } exports.WalletClient = WalletClient; //# sourceMappingURL=wallet.js.map