UNPKG

@astonic-io/astonic-sdk

Version:

Official SDK for interacting with the Astonic Protocol

59 lines (58 loc) 2.42 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.ChainClient = void 0; const ethers_1 = require("ethers"); const utils_1 = require("./utils"); class ChainClient { constructor(signerOrProvider) { (0, utils_1.validateSignerOrProvider)(signerOrProvider); this.signerOrProvider = signerOrProvider; } getSigner() { return __awaiter(this, void 0, void 0, function* () { return this.signerOrProvider; }); } getChainId() { var _a; return __awaiter(this, void 0, void 0, function* () { let chainId = 0; if (ethers_1.Signer.isSigner(this.signerOrProvider)) { const network = yield ((_a = this.signerOrProvider.provider) === null || _a === void 0 ? void 0 : _a.getNetwork()); if (network) { chainId = network.chainId; } } else if (ethers_1.providers.Provider.isProvider(this.signerOrProvider)) { const network = yield this.signerOrProvider.getNetwork(); if (network) { chainId = network.chainId; } } if (chainId === 0) { throw new Error('Could not get chainId from signer or provider'); } return chainId; }); } populateTransaction(tx) { return __awaiter(this, void 0, void 0, function* () { if (ethers_1.Signer.isSigner(this.signerOrProvider)) { return this.signerOrProvider.populateTransaction(tx); } else { return tx; } }); } } exports.ChainClient = ChainClient;