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

  1. Connection Management

    • Implement reconnection logic with exponential backoff

    • Keep track of subscription state

    • Handle connection drops gracefully

  2. Event Processing

    • Process events in order

    • Maintain local state

    • Handle out-of-order events

  3. Performance

    • Subscribe only to needed topics

    • Batch event processing when possible

    • Monitor memory usage for stored events

Example Implementation

Debugging Tips

  1. Use the debug endpoint to monitor WebSocket state:

  1. Enable verbose logging:

  1. Monitor connection health:

Last updated