UNPKG

@accret/api-client

Version:

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

48 lines 1.69 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getEVMTokenPrice = getEVMTokenPrice; exports.getSolanaTokenPrice = getSolanaTokenPrice; const moralis_1 = __importDefault(require("moralis")); const axios_1 = __importDefault(require("axios")); /** * @description Fetches the current price of an EVM token using Moralis SDK. * @param tokenAddress The address of the token to fetch the price for. * @param network The EVM chain to fetch the price from. * @returns The current price of the token. */ async function getEVMTokenPrice(tokenAddress, network) { try { const response = await moralis_1.default.EvmApi.token.getTokenPrice({ chain: network, address: tokenAddress, }); return response; } catch (error) { console.error("Error getting EVM token price:", error); throw error; } } /** * @description Fetches the current price of a Solana token using Jupiter API. * @param tokenAddress The address of the Solana token to fetch the price for. * @returns An object of the current price of the token. */ async function getSolanaTokenPrice(tokenAddress) { try { const response = await axios_1.default.get(`https://lite-api.jup.ag/price/v2`, { params: { ids: tokenAddress, }, }); return response.data.data; } catch (error) { console.error("Error getting Solana token price:", error); throw error; } } //# sourceMappingURL=token-price.js.map