Get Token Details
Description
Authentication
Request
Headers
Content-Type: application/json
Query Parameters
Parameter
Type
Required
Description
Response
Success Response
Error Response
Example Usage
// Basic token details fetcher
async function getTokenDetails(tokenMintAddress: string) {
try {
const response = await fetch(
`https://api.heyhal.xyz/api/v1/coin/details?token=${tokenMintAddress}`
);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const tokenDetails = await response.json();
return tokenDetails;
} catch (error) {
console.error('Error fetching token details:', error);
throw error;
}
}
// Token Details Manager with caching
class TokenDetailsManager {
private cache: Map<string, {
data: TokenDetailsResponse;
timestamp: number;
}> = new Map();
private readonly CACHE_DURATION = 30000; // 30 seconds
async getDetails(tokenMintAddress: string): Promise<TokenDetailsResponse> {
// Check cache
const cached = this.cache.get(tokenMintAddress);
if (cached && Date.now() - cached.timestamp < this.CACHE_DURATION) {
return cached.data;
}
// Fetch fresh data
const details = await getTokenDetails(tokenMintAddress);
// Update cache
this.cache.set(tokenMintAddress, {
data: details,
timestamp: Date.now()
});
return details;
}
clearCache(tokenMintAddress?: string) {
if (tokenMintAddress) {
this.cache.delete(tokenMintAddress);
} else {
this.cache.clear();
}
}
}
Implementation Notes
Last updated