UNPKG

pontus-x_cli

Version:

Command Line Interface for the Pontus-X Data Space Ecosystem.

46 lines 2.22 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Connection = void 0; const dotenv_1 = __importDefault(require("dotenv")); dotenv_1.default.config(); const config_1 = require("../config"); const ethers_1 = require("ethers"); const nautilus_1 = require("@deltadao/nautilus"); class Connection { constructor(wallet, nautilus, networkConfig, pricingConfig) { this.wallet = wallet; this.nautilus = nautilus; this.networkConfig = networkConfig; this.pricingConfig = pricingConfig; } static async connect() { if (!process.env.NETWORK) { console.error(`Set your network in the .env file. Supported networks are ` + `${Object.values(config_1.Network).join(', ')}.`); process.exit(1); } const selectedEnvNetwork = process.env.NETWORK.toUpperCase(); if (!(selectedEnvNetwork in config_1.Network)) { console.error(`Invalid network selection: ${selectedEnvNetwork}. Supported networks are ${Object.values(config_1.Network).join(', ')}.`); process.exit(1); } console.log(`Your selected network is ${config_1.Network[selectedEnvNetwork]}`); const networkConfig = config_1.NETWORK_CONFIGS[selectedEnvNetwork]; const pricingConfig = config_1.PRICING_CONFIGS[selectedEnvNetwork]; if (!process.env.PRIVATE_KEY) { console.error(`Login to retrieve your private key using "pontusx-cli login keyFile.json"` + ` and do not forget to logout when finished.`); process.exit(1); } const provider = new ethers_1.providers.JsonRpcProvider(networkConfig.nodeUri); const wallet = new ethers_1.Wallet(process.env.PRIVATE_KEY, provider); const nautilus = await nautilus_1.Nautilus.create(wallet, networkConfig); console.log(`Connected as ${wallet.address}`); return new Connection(wallet, nautilus, networkConfig, pricingConfig); } } exports.Connection = Connection; //# sourceMappingURL=connection.js.map