Get SOL Price
Description
Authentication
Request
Headers
Content-Type: application/json
Response
Success Response
Error Response
Example Usage
// Basic fetch
async function getSOLPrice() {
try {
const response = await fetch('https://api.heyhal.xyz/api/v1/coin/sol-price');
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const { price } = await response.json();
return price;
} catch (error) {
console.error('Error fetching SOL price:', error);
throw error;
}
}
// With client-side caching
class SOLPriceManager {
private cache: {
price: number;
timestamp: number;
} | null = null;
private readonly CACHE_DURATION = 60000; // 60 seconds
async getPrice(): Promise<number> {
// Check cache
if (this.cache &&
Date.now() - this.cache.timestamp < this.CACHE_DURATION) {
return this.cache.price;
}
// Fetch new price
const response = await fetch('https://api.heyhal.xyz/api/v1/coin/sol-price');
const { price } = await response.json();
// Update cache
this.cache = {
price,
timestamp: Date.now()
};
return price;
}
clearCache() {
this.cache = null;
}
}
Implementation Notes
Best Practices
Last updated