Skip to main content
See it in action: Check out our Live Streaming Dashboard to see real-time price updates across multiple chains before you build your own.

Tutorial overview

In this tutorial, you’ll learn how to:
  • Connect to the DexPaprika streaming API
  • Receive real-time price updates
  • Handle connection errors gracefully
  • Build a simple price display
Time to complete: 5 minutes Prerequisites: Basic JavaScript knowledge

Step 1: Choose Your Asset

For this tutorial, we’ll stream the price of Ethereum (WETH).

Finding Token Addresses

Use the REST API to find token addresses:
  1. Search by name or symbol using the Search Endpoint:
curl "https://api.dexpaprika.com/search?query=WETH"
  1. Get network list using the Networks Endpoint:
curl "https://api.dexpaprika.com/networks"

Common Token Addresses

Or use these verified addresses for popular tokens:
Chain: ethereum
WETH: 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
USDC: 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48

Step 2: Test with cURL

First, let’s verify the stream works with a simple cURL command:
curl -N "https://streaming.dexpaprika.com/stream?method=t_p&chain=ethereum&address=0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2&limit=3"
You should see output like:
data: {"a":"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2","c":"ethereum","p":"3997.5514026436525223","t":1761733397}
event: t_p

data: {"a":"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2","c":"ethereum","p":"3998.1234567890123456","t":1761733398}
event: t_p
The limit=3 parameter closes the stream after 3 events - perfect for testing!

Step 3: JavaScript Implementation

Here’s how to connect to the streaming API using JavaScript:
// Connect to streaming API
const url = new URL('https://streaming.dexpaprika.com/stream');
url.searchParams.set('method', 't_p');
url.searchParams.set('chain', 'ethereum');
url.searchParams.set('address', '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2');

const eventSource = new EventSource(url.toString());

// Handle price updates
eventSource.addEventListener('t_p', (event) => {
    const data = JSON.parse(event.data);
    const price = parseFloat(data.p);
    console.log(`WETH Price: $${price.toFixed(2)}`);
});

// Handle errors with reconnection
eventSource.onerror = () => {
    console.log('Connection lost, reconnecting...');
    eventSource.close();
    // Implement reconnection logic here
};
🎯 Live Example: See this code in action in our Interactive Streaming Dashboard - watch 6 tokens stream live across Ethereum, Solana, and BSC with real-time updates, connection status, and latency monitoring.

Step 4: Customize Your Stream

Stream Different Tokens

Modify the URL parameters to stream any token:
// Bitcoin on Ethereum
url.searchParams.set('chain', 'ethereum');
url.searchParams.set('address', '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599');

// SOL on Solana
url.searchParams.set('chain', 'solana');
url.searchParams.set('address', 'So11111111111111111111111111111111111111112');

// BNB on BSC
url.searchParams.set('chain', 'bsc');
url.searchParams.set('address', '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c');

Add Multiple Assets

To stream multiple assets, switch to the POST method:

Understanding the Code

Key Components

The EventSource API is the browser’s built-in way to handle SSE:
const eventSource = new EventSource(url);
eventSource.addEventListener('t_p', handler);
It automatically handles:
  • Persistent connections
  • Automatic reconnection
  • Event parsing
The onerror callback handles disconnections:
eventSource.onerror = () => {
    // Implement exponential backoff
    const delay = baseDelay * Math.pow(2, attempts);
    setTimeout(reconnect, delay);
};
Each event contains:
{
    "a": "address",     // Token contract address
    "c": "chain",       // Blockchain network
    "p": "price",       // USD price as string
    "t": timestamp      // Unix timestamp
}

Implementation Notes

Browser Support

  • EventSource API works in all modern browsers
  • For direct browser connections, you’ll need to handle CORS (use a backend proxy)
  • No issues when streaming from server-side (Node.js, Python, etc.)

Best Practices

  • Implement exponential backoff for reconnection
  • Handle both connection errors and SSE error events
  • Parse prices as floats to maintain precision
  • Close connections properly on page unload

See It Live

🚀 Live Streaming Dashboard

Experience the API in action! Our interactive demo streams 6 cryptocurrencies in real-time across Ethereum, Solana, and BSC. Watch live price updates, connection status, latency metrics, and update statistics. Built with React and deployed on Vercel - perfect reference implementation showing POST /stream with multiple assets.What you’ll see:
  • Real-time price updates every ~1 second
  • Multi-chain token streaming (ETH, SOL, BSC)
  • Live connection status and latency
  • Price change indicators and trends
  • Total updates and uptime metrics

Next Steps

Congratulations! You’ve built your first streaming application. Here’s what to explore next:

Get Help