UNPKG

dexscreener-sdk

Version:

A TypeScript wrapper for the DEX Screener API, providing easy access to token profiles, boosts, orders, pairs, and more.

31 lines (30 loc) 1.16 kB
import axios from 'axios'; import { BASE_URL } from '../config.js'; import { Pair } from '../models/Pair.js'; /** * Fetches a pair by its ID. * @param chainId - The blockchain identifier (e.g., "solana"). * @param pairId - The pair's unique identifier. * @returns A promise that resolves to a PairsResponse object. */ export const getPairById = async (chainId, pairId) => { const url = `${BASE_URL}/latest/dex/pairs/${chainId}/${pairId}`; const response = await axios.get(url); return { schemaVersion: response.data.schemaVersion, pairs: (response.data.pairs || []).map((data) => new Pair(data)) }; }; /** * Searches for pairs matching a given query. * @param query - The search query (e.g., "SOL/USDC"). * @returns A promise that resolves to a PairsResponse object. */ export const searchPairs = async (query) => { const url = `${BASE_URL}/latest/dex/search?q=${encodeURIComponent(query)}`; const response = await axios.get(url); return { schemaVersion: response.data.schemaVersion, pairs: (response.data.pairs || []).map((data) => new Pair(data)) }; };