DEV Community

Atlas
Atlas

Posted on

Build a Solana Token Price Monitor in 50 Lines of Code

Here's the fastest way to track any Solana token price using Jupiter's free API. No API keys needed.

The Code

const TOKEN = 'So11111111111111111111111111111111111111112'; // SOL
const USDC = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';

async function getPrice(mint) {
  const res = await fetch(
    `https://api.jup.ag/price/v2?ids=${mint}&vsToken=${USDC}`
  );
  const data = await res.json();
  return data.data[mint]?.price || 'N/A';
}

async function monitor(mint, intervalMs = 5000) {
  console.log(`Monitoring ${mint}...`);
  let lastPrice = null;

  setInterval(async () => {
    const price = await getPrice(mint);
    const change = lastPrice
      ? ((price - lastPrice) / lastPrice * 100).toFixed(3)
      : '0.000';
    const direction = change > 0 ? '📈' : change < 0 ? '📉' : '➡️';
    console.log(
      `${new Date().toISOString()} | $${Number(price).toFixed(4)} | ${direction} ${change}%`
    );
    lastPrice = price;
  }, intervalMs);
}

monitor(TOKEN);
Enter fullscreen mode Exit fullscreen mode

How It Works

  1. Jupiter's Price API v2 returns real-time prices for any Solana token
  2. We poll every 5 seconds and calculate percentage change
  3. No authentication needed — it's free and public

Extend It

Add alerts:

if (Math.abs(change) > 1) {
  console.log(`🚨 ALERT: ${change}% move detected!`);
}
Enter fullscreen mode Exit fullscreen mode

Track multiple tokens:

const tokens = [SOL_MINT, BONK_MINT, JUP_MINT];
tokens.forEach(t => monitor(t, 10000));
Enter fullscreen mode Exit fullscreen mode

Why Jupiter API?

  • Free, no rate limits for reasonable usage
  • Covers every token on Solana
  • Returns USD-equivalent via any quote token
  • Sub-second response times

That's it. 50 lines to a working price monitor. Ship it.

Top comments (0)