API Integration
Overview
Integrate X804 reward data into your own applications using our API and WebSocket connections.
PumpPortal Integration
WebSocket Connection
Monitor trades in real-time:
const CONTRACT_ADDRESS = '...';
// Connect to PumpPortal
const ws = new WebSocket('wss://pumpportal.fun/api/data');
ws.onopen = () => {
console.log('Connected to PumpPortal');
// Subscribe to token
ws.send(JSON.stringify({
method: 'subscribe',
keys: [CONTRACT_ADDRESS]
}));
};
ws.onmessage = (event) => {
const trade = JSON.parse(event.data);
console.log('Trade detected:', {
type: trade.txType,
amount: trade.tokenAmount,
sol: trade.solAmount,
wallet: trade.signature.substring(0, 8)
});
};
ws.onerror = (error) => {
console.error('WebSocket error:', error);
};Trade Data Structure
interface Trade {
signature: string; // Transaction signature
mint: string; // Token contract address
traderPublicKey: string; // Trader wallet
txType: 'buy' | 'sell'; // Trade type
tokenAmount: number; // Token amount
solAmount: number; // SOL amount
timestamp: number; // Unix timestamp
}X804 API Endpoints
Get Recent Rewards
GET /api/rewardsParameters:
limit(optional): Number of results (default: 50, max: 100)offset(optional): Pagination offset
Response:
{
"success": true,
"data": [
{
"txHash": "a1b2c3d4e5f6g7h8...",
"wallet": "So1ana123...",
"amount": "0.0523",
"timestamp": 1703123456
}
],
"total": 1247
}Get Statistics
GET /api/statsResponse:
{
"success": true,
"data": {
"totalRewards": "125.4523",
"totalRecipients": 1247,
"last24h": "12.3456",
"averageReward": "0.1005"
}
}Get Wallet Rewards
GET /api/rewards/:walletAddressResponse:
{
"success": true,
"data": {
"wallet": "So1ana123...",
"totalReceived": "2.4567",
"rewardCount": 23,
"lastReward": {
"amount": "0.0523",
"timestamp": 1703123456,
"txHash": "a1b2c3d4..."
}
}
}Code Examples
React Integration
import { useEffect, useState } from 'react';
function RewardsDashboard() {
const [rewards, setRewards] = useState([]);
useEffect(() => {
// Fetch initial rewards
fetch('https://x804.io/api/rewards')
.then(res => res.json())
.then(data => setRewards(data.data));
// Connect to WebSocket for real-time updates
const ws = new WebSocket('wss://x804.io/ws');
ws.onmessage = (event) => {
const newReward = JSON.parse(event.data);
setRewards(prev => [newReward, ...prev]);
};
return () => ws.close();
}, []);
return (
<div>
{rewards.map(reward => (
<div key={reward.txHash}>
{reward.wallet}: {reward.amount} SOL
</div>
))}
</div>
);
}Node.js Backend
const express = require('express');
const WebSocket = require('ws');
const app = express();
const PORT = 3000;
// Store recent rewards
let recentRewards = [];
// Connect to PumpPortal
const ws = new WebSocket('wss://pumpportal.fun/api/data');
ws.on('message', (data) => {
const trade = JSON.parse(data);
if (trade.mint === CONTRACT_ADDRESS) {
// Process reward
const reward = processReward(trade);
recentRewards.unshift(reward);
// Keep only last 100
recentRewards = recentRewards.slice(0, 100);
}
});
// API endpoint
app.get('/rewards', (req, res) => {
res.json({
success: true,
data: recentRewards
});
});
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});Python Integration
import asyncio
import websockets
import json
CONTRACT_ADDRESS = '...'
async def monitor_trades():
uri = 'wss://pumpportal.fun/api/data'
async with websockets.connect(uri) as ws:
# Subscribe to token
await ws.send(json.dumps({
'method': 'subscribe',
'keys': [CONTRACT_ADDRESS]
}))
async for message in ws:
trade = json.loads(message)
print(f"Trade: {trade['txType']} - {trade['solAmount']} SOL")
asyncio.run(monitor_trades())Rate Limits
API: 100 requests per minute
WebSocket: No limit on messages
Historical data: Last 30 days
Best Practices
Handle Reconnections: WebSocket connections may drop
Cache Data: Store historical data locally
Error Handling: Always handle API errors gracefully
Rate Limiting: Respect API rate limits
Webhook Alternative: Contact us for webhook integration
Support
Need help integrating?
Join our Telegram: t.me/x804
Check examples: GitHub
Read docs: x804.gitbook.io
Build with X804! Create your own reward tracking applications.
Last updated

