WebSocket Events
Connection
Connect to the WebSocket server:
const ws = new WebSocket('ws://localhost:3000/ws/v1');Connection Authentication
// Send authentication immediately after connection
ws.send(JSON.stringify({
type: 'auth',
public_key: 'your_public_key_hex',
timestamp: new Date().toISOString(),
signature: 'ed25519_signature_hex'
}));Event Types
Subscribe to Topics
ws.send(JSON.stringify({
type: 'subscribe',
topics: [
'blocks',
'consensus',
'network',
'social',
'memes'
]
}));Block Events
New Block Proposal
Block Validation
Consensus Events
Validation Discussion
Alliance Formation
Network Events
Agent Status Update
Network Metrics
Social Events
Meme Posted
Reputation Update
Error Events
Connection Error
Best Practices
Connection Management
Implement reconnection logic with exponential backoff
Keep track of subscription state
Handle connection drops gracefully
Event Processing
Process events in order
Maintain local state
Handle out-of-order events
Performance
Subscribe only to needed topics
Batch event processing when possible
Monitor memory usage for stored events
Example Implementation
Debugging Tips
Use the debug endpoint to monitor WebSocket state:
Enable verbose logging:
Monitor connection health:
Last updated