Real-time event streaming for lobby, contract, bounty, and storage updates
Explore the REST API documentation for all Hashi microservices:
WebSocket URL
Connect to the WebSocket server using a valid Privy JWT token in the query string. The token is used to authenticate and identify the player.
const token = 'eyJhbGciOiJS...'; // Privy JWT token
const ws = new WebSocket(`wss://socket.dev.hashi.gg?token=${token}`);
ws.onopen = () => {
console.log('Connected to Hashi WebSocket');
};
ws.onmessage = (event) => {
const message = JSON.parse(event.data);
console.log('Received:', message.type, message.data);
};
ws.onclose = () => {
console.log('Disconnected');
};
All messages from the server follow this structure:
{
"type": "contract:event" | "lobby:event" | "storage:event" | "connected" | "pong" | "error",
"data": { ... }
}
Clients can send these message types:
| Type | Description |
|---|---|
ping |
Keep-alive ping, server responds with pong |
subscribe |
Subscribe to a lobby room for targeted events |
unsubscribe |
Unsubscribe from a lobby room |
Contract events are broadcast globally to all connected clients. These events track the lifecycle of smart contract interactions.
Contract record created in database
Blockchain transaction submitted
Transaction confirmed on-chain
Contract rolled back or deleted
Player funded their stake
Player submitted outcome and proof
Player contested mediation decision
Mediator submitted decision
Admin made final decision
Payout completed and distributed
{
"type": "contract:event",
"data": {
"type": "contract.initialized",
"contractId": "550e8400-e29b-41d4-a716-446655440000",
"lobbyId": "ABC123",
"timestamp": "2024-01-15T10:30:00.000Z",
"payload": {
// Full Contract object
}
}
}
Lobby events are broadcast to room members only. Players automatically join the room when they're a lobby participant.
New lobby created
Player joined the lobby
Player left the lobby
Lobby deleted (last player left)
{
"type": "lobby:event",
"data": {
"type": "lobby.joined",
"lobbyId": "550e8400-e29b-41d4-a716-446655440000",
"lobbyCode": "ABC123",
"timestamp": "2024-01-15T10:30:00.000Z",
"payload": {
"lobby": { /* Full Lobby object */ },
"playerId": "...",
"participantCount": 2
}
}
}
Storage events are broadcast to lobby room members for the contract's associated lobby.
External URL stored for a contract
Presigned upload URL generated (file not yet uploaded)
Multipart upload completed
Multipart upload aborted
Storage item deleted
{
"type": "storage:event",
"data": {
"type": "storage.presigned_url_created",
"storageId": "550e8400-e29b-41d4-a716-446655440000",
"contractId": "...",
"lobbyId": "...",
"playerId": "...",
"timestamp": "2024-01-15T10:30:00.000Z",
"payload": {
"storage": { /* Full Storage object */ }
}
}
}
If authentication fails or an error occurs, you'll receive an error message:
{
"type": "error",
"data": {
"message": "Authentication failed",
"code": "AUTH_ERROR"
}
}