WebSocket API
Stream real-time x402 payment data, transaction events, and network activity via high-performance WebSocket connections.
Overview
WebSocket URL: wss://api.yuzu402.dev/data
Connection Limits:
Standard: 5 concurrent connections, 50 messages/second
Premium: 20 concurrent connections, 200 messages/second
Connecting
JavaScript/TypeScript
const ws = new WebSocket('wss://api.yuzu402.dev/data');
ws.onopen = () => {
console.log('Connected to Yuzu402 WebSocket');
// Subscribe to payments
ws.send(JSON.stringify({
method: 'subscribe',
keys: ['payments']
}));
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Received:', data);
};
ws.onerror = (error) => {
console.error('WebSocket error:', error);
};
ws.onclose = (event) => {
console.log('Connection closed:', event.code, event.reason);
};Python
Authentication
For WebSocket connections, include your API key in the initial connection message:
You'll receive a confirmation:
Subscription Methods
Subscribe to Channels
Available Channels:
payments- All payment transactions across the networkverifications- Payment verification eventssettlements- Payment settlement confirmations{WALLET_ADDRESS}- Events for a specific wallet address
Success Response:
Subscribe to Specific Wallet
Unsubscribe
Event Types
Payment Event
Emitted when a payment transaction occurs on the x402 network.
Verification Event
Emitted when a payment is verified by a facilitator.
Settlement Event
Emitted when a payment is settled and confirmed on-chain.
Error Event
Advanced Usage
Reconnection Logic
React Hook Example
Best Practices
Implement Reconnection: Handle connection drops gracefully
Authenticate Early: Send authentication immediately after connecting
Manage Subscriptions: Track subscriptions for reconnection
Handle Errors: Monitor error events and log them
Rate Limiting: Respect message rate limits
Heartbeat: Implement ping/pong for connection health
Clean Disconnection: Close connections properly when done
Heartbeat/Ping-Pong
Keep the connection alive with periodic pings:
Error Codes
AUTHENTICATION_FAILED
Invalid API key
SUBSCRIPTION_FAILED
Invalid subscription key
RATE_LIMIT_EXCEEDED
Too many messages
CONNECTION_LIMIT
Too many concurrent connections
Next Steps
View Lightning API for payment endpoints
Explore x402 Protocol Documentation
Check Examples for complete implementations
Learn about Error Handling
Last updated

