UNPKG

nodana

Version:
91 lines (86 loc) 2.8 kB
#!/usr/bin/env node "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Nodana = void 0; const clients_1 = require("./clients"); const types_1 = require("./types"); const utils_1 = require("./utils"); class Nodana { constructor(settings) { this.config = new utils_1.NodanaConfig(settings); this.wallet = new clients_1.WalletClient(this.config); } } exports.Nodana = Nodana; /** * return the arguments of the command except node and index.ts */ const getArgs = () => { // We retrieve all the command argumnts except the first 2 const args = process.argv.slice(2); return args; }; /** * Command Help */ const printCommandHelp = () => { const help = ` nodana SOLANA CLI command to retrieve information. Example: $ nodana --wallet-balance <WALLET_ADDR> $ nodana --airdrop 1 <WALLET_ADDR> `; console.log(help); }; const symbols = getArgs(); // Print help if no arguments if (symbols.length === 0) { printCommandHelp(); process.exit(0); } if (process.argv[2] === "--wallet-balance") { const wallet = process.argv[3]; if (!wallet) { console.log("Please provide a wallet address"); process.exit(0); } console.log(`Retrieving balance of wallet: ${wallet}`); const nodana = new Nodana({ network: types_1.Network.Devnet }); nodana.wallet.fetchBalance(process.argv[3]).then(console.log); } if (process.argv[2] === "--airdrop") { const sol = process.argv[3]; if (!sol) { console.log("Please provide amount"); process.exit(0); } const wallet = process.argv[4]; if (!wallet) { console.log("Please provide a wallet address"); process.exit(0); } if (parseFloat(sol) > 1) { console.log("Not allowed to airdrop more than 1 SOL"); process.exit(0); } console.log(`Airdrop 🚀 to wallet: ${wallet}`); const nodana = new Nodana({ network: types_1.Network.Devnet }); nodana.wallet.requestAirDrop(wallet, parseFloat(sol)).then(console.log); } __exportStar(require("./types"), exports); //# sourceMappingURL=index.js.map