UNPKG

@accret/api-client

Version:

A comprehensive SDK for blockchain data access via Moralis, Alchemy, and Shyft APIs

65 lines 2.41 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createAlchemyClient = createAlchemyClient; exports.InitializeMoralis = InitializeMoralis; exports.InitializeShyft = InitializeShyft; const moralis_1 = __importDefault(require("moralis")); const alchemy_sdk_1 = require("alchemy-sdk"); const js_1 = require("@shyft-to/js"); /** * Creates an Alchemy client instance. * @param apiKey - The Alchemy API key. * @param network - The Alchemy network to connect to. * @throws An error if the API key is invalid or if the network is not supported. * @returns An instance of the Alchemy client. */ function createAlchemyClient(apiKey, network) { if (!apiKey || typeof apiKey !== "string" || apiKey.trim().length === 0) { throw new Error("Invalid API key: API key must be a non-empty string"); } return new alchemy_sdk_1.Alchemy({ apiKey, network, }); } /** * Initializes the Moralis SDK. * @param apiKey - The Moralis API key. * @description Initializes the Moralis SDK with the provided API key. * @throws Will throw an error if the API key is invalid or if Moralis is already * @returns An instance of the Moralis SDK. */ async function InitializeMoralis(apiKey) { if (!apiKey || typeof apiKey !== "string" || apiKey.trim().length === 0) { throw new Error("Invalid API key: API key must be a non-empty string"); } if (moralis_1.default.Core.isStarted) { return moralis_1.default; } else { await moralis_1.default.start({ apiKey }); } return moralis_1.default; } /** * Initializes the Shyft SDK. * @param apiKey - The Shyft API key. * @description Initializes the Shyft SDK with the provided API key. * @throws Will throw an error if the API key is invalid. * @throws Will throw an error if the Shyft SDK is already initialized. * @returns An instance of the Shyft SDK. */ async function InitializeShyft(apiKey) { if (!apiKey || typeof apiKey !== "string" || apiKey.trim().length === 0) { throw new Error("Invalid API key: API key must be a non-empty string"); } const shyft = new js_1.ShyftSdk({ apiKey, network: js_1.Network.Mainnet, }); return shyft; } //# sourceMappingURL=index.js.map