King of the Hill
Description
Authentication
Request
Headers
Content-Type: application/json
Query Parameters
Parameter
Type
Required
Description
Response
Success Response - Get Current King
Success Response - Update Token Status
Error Response
Example Usage
// Function to get current King of the Hill
async function getCurrentKing() {
try {
const response = await fetch(
'https://api.heyhal.xyz/api/v1/coin/king-of-the-hill'
);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const kingToken = await response.json();
return kingToken;
} catch (error) {
console.error('Error fetching King of the Hill:', error);
throw error;
}
}
// Function to check/update token status
async function checkKingStatus(tokenMintAddress: string) {
try {
const response = await fetch(
`https://api.heyhal.xyz/api/v1/coin/king-of-the-hill?token=${tokenMintAddress}`
);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const result = await response.json();
return result.success;
} catch (error) {
console.error('Error checking King status:', error);
throw error;
}
}
// Example usage with UI updates
async function displayKingOfTheHill() {
try {
const king = await getCurrentKing();
if (king) {
console.log(`
Current King of the Hill:
Token: ${king.name} (${king.symbol})
Achieved at: ${new Date(Number(king.kingOfTheHillTimeStamp) * 1000).toLocaleString()}
Creator: ${king.creator.username || king.creator.walletAddress}
Comments: ${king.comments.length}
`);
} else {
console.log('No token has achieved King of the Hill status yet');
}
} catch (error) {
console.error('Error displaying King of the Hill:', error);
}
}
Implementation Notes
Best Practices
Last updated