Appearance
WebSocket
Two WebSocket transports: one for chain events, one for bridge swap progress.
Use WebSocket in a browser showing live progress. For a server that must not miss an event, use webhooks — they are retried and survive your process restarting.
Chain events
wss://api.testnet.kriptonyx.com/socket/websocket?vsn=2.0.0Phoenix channel protocol: join a topic, then receive events on it. Messages are JSON arrays framed as [join_ref, ref, topic, event, payload].
Topics
| Topic | Event | Payload |
|---|---|---|
blocks:new_block | new_block | Newly indexed block |
transactions:new_transaction | new_transaction | Newly indexed transaction |
addresses:{address_hash} | balance, transaction | Per-address updates |
tokens:{address_hash} | token_transfer | Token transfers |
Joining a topic
js
const ws = new WebSocket('wss://api.testnet.kriptonyx.com/socket/websocket?vsn=2.0.0');
ws.onopen = () => {
ws.send(JSON.stringify(['1', '1', 'blocks:new_block', 'phx_join', {}]));
// Phoenix closes an idle socket; a heartbeat keeps it open.
setInterval(() => {
ws.send(JSON.stringify([null, '0', 'phoenix', 'heartbeat', {}]));
}, 30000);
};
ws.onmessage = ({ data }) => {
const [, , topic, event, payload] = JSON.parse(data);
if (event === 'new_block') console.log('block', payload.block_number);
};Send the heartbeat
Without a periodic phoenix heartbeat the server closes the connection as idle, and a client that does not reconnect silently stops receiving events.
Watching one address
js
ws.send(JSON.stringify(['1', '2', `addresses:${address.toLowerCase()}`, 'phx_join', {}]));Address topics use the lowercase form.
Bridge swap events
wss://bridge.testnet.kriptonyx.com/wsA simpler protocol: subscribe to one swap, receive its lifecycle.
js
const ws = new WebSocket('wss://bridge.testnet.kriptonyx.com/ws');
ws.onopen = () =>
ws.send(JSON.stringify({ type: 'subscribe', swap_id: swapId }));
ws.onmessage = ({ data }) => {
const msg = JSON.parse(data);
if (msg.type === 'subscribed') console.log('watching', msg.swap_id);
if (msg.type === 'swap_update') {
console.log(msg.event, msg.tx_hash ?? '');
if (msg.event === 'target_token_sent') console.log('done:', msg.tx_hash);
}
};The event names are the same catalogue used by webhooks, so the two transports are interchangeable.
Reconnecting
Both sockets can drop. Reconnect with backoff and re-join your topics, then reconcile anything missed:
- Chain events — query the chain data API for the gap.
- Bridge swaps — call
GET /api/swap/:id/events, which returns the full lifecycle, so nothing is lost.