Sei WebSocket Guide
WebSocket connections provide real-time access to Sei blockchain data, enabling your applications to receive instant updates for new blocks, transactions, and smart contract events without polling.
Why Use WebSockets with Sei?
Advantages
- Sub-second Updates: Get notified of events as they happen (~400ms block time)
- Lower Latency: No polling delays
- Reduced Bandwidth: Only receive data when it changes
- Real-time Trading: Perfect for DeFi applications needing instant updates
- Event-Driven Architecture: React to blockchain events immediately
Common Use Cases
- Trading Bots: Instant price and liquidity updates
- Portfolio Trackers: Real-time balance changes
- DeFi Dashboards: Live yield and farming data
- Gaming Applications: Immediate game state updates
- Analytics Platforms: Real-time blockchain metrics
WebSocket Endpoints
wss://api.blockeden.xyz/sei/<your-api-key>
EVM WebSocket Subscriptions
Sei's EVM layer supports Ethereum-compatible WebSocket subscriptions.
Basic Connection
const ws = new WebSocket('wss://api.blockeden.xyz/sei/<your-api-key>');
ws.onopen = function(event) {
console.log('Connected to Sei WebSocket');
};
ws.onmessage = function(event) {
const data = JSON.parse(event.data);
console.log('Received:', data);
};
ws.onerror = function(error) {
console.error('WebSocket error:', error);
};
ws.onclose = function(event) {
console.log('WebSocket closed:', event.code, event.reason);
};