@accret/api-client
Version:
A comprehensive SDK for blockchain data access via Moralis, Alchemy, and Shyft APIs
70 lines • 2.99 kB
JavaScript
import { getTokenMetadata, getTokenPrice, getHistoricalTokenPrice, } from "./token";
import { InitializeMoralis } from "./config";
import { getTokensForWallet, getTransactionHistory } from "./portfolio";
import { getAccretSupportedChain, getChainIdentifiers, } from "./utils/supportedChain";
import { setAPIKeys } from "./constants";
import { AccretSupportedChain } from "./types";
import { HistoricalPriceInterval } from "alchemy-sdk";
export class AccretClient {
/**
* Returns the singleton instance of the AccretClient.
* If the instance does not exist, it creates a new one.
* @returns The singleton instance of AccretClient.
*/
constructor() {
this.getTokenMetadata = getTokenMetadata;
this.getTokenPrice = getTokenPrice;
this.getHistoricalTokenPrice = getHistoricalTokenPrice;
this.getTokensForWallet = getTokensForWallet;
this.getTransactionHistory = getTransactionHistory;
this.getAccretSupportedChain = getAccretSupportedChain;
this.getChainIdentifiers = getChainIdentifiers;
// Exporting types and constants
this.AccretSupportedChain = AccretSupportedChain;
this.HistoricalPriceInterval = HistoricalPriceInterval;
if (!AccretClient.instance) {
AccretClient.instance = this;
return;
}
return AccretClient.instance;
}
/**
* Initializes the Accret client with the provided API keys.
* @param alchemyApiKey - The Alchemy API key.
* @param moralisApiKey - The Moralis API key.
* @param shyftApiKey - The Shyft API key.
* @param heliusApiKey - The Helius API key.
* @throws An error if any of the API keys are invalid.
*/
async configure({ alchemyApiKey, moralisApiKey, shyftApiKey, heliusApiKey, }) {
if (!alchemyApiKey ||
typeof alchemyApiKey !== "string" ||
alchemyApiKey.trim().length === 0) {
throw new Error("Invalid Alchemy API key: API key must be a non-empty string");
}
if (!moralisApiKey ||
typeof moralisApiKey !== "string" ||
moralisApiKey.trim().length === 0) {
throw new Error("Invalid Moralis API key: API key must be a non-empty string");
}
if (!shyftApiKey ||
typeof shyftApiKey !== "string" ||
shyftApiKey.trim().length === 0) {
throw new Error("Invalid Shyft API key: API key must be a non-empty string");
}
if (!heliusApiKey ||
typeof heliusApiKey !== "string" ||
heliusApiKey.trim().length === 0) {
throw new Error("Invalid Helius API key: API key must be a non-empty string");
}
await setAPIKeys({
alchemyApiKey,
moralisApiKey,
shyftApiKey,
heliusApiKey,
});
await InitializeMoralis(moralisApiKey);
return AccretClient.instance;
}
}
//# sourceMappingURL=index.js.map