WebSocket events (Centrifugo)
Centrifugo v6 WebSocket protocol in Minter Explorer: explorer:blocks, explorer:transactions, and explorer:address:<mx_lower> channels, live_publish.rs payloads, recover: true, and cursor HTTP catchup.
live_publish.rs in Minter Explorer broadcasts committed events to Centrifugo v6 right after PostgreSQL commits each block (public Mainnet endpoint: wss://explorer.minter.network/connection/websocket). Channels run with an in-memory recovery ring of history_size = 20, history_ttl = 300s, and force_recovery = true. Because Tendermint v0.34.19 finalizes blocks after > 2/3 validator signatures without chain reorganizations, published frames reflect committed state (see single-block finality).
Channels and legacy aliases
In explorer:address:<mx_lower>, write both the mx prefix and the 40 hex characters in lowercase; in the legacy <Mx...> channel, capitalize M and keep the 40 hex characters lowercase. live_publish.rs does not publish a separate explorer:pools channel: pool swap receipts stream on explorer:transactions.
v2 channel | Legacy aliases | pub.data payload (live_publish.rs) |
|---|---|---|
explorer:blocks | blocks | { "block": blockCard, "totals": { "latest_block_height": "...", "total_transactions": "..." } } |
explorer:transactions | transactions, transactions_100 | Hydrated committed txCard object (including 0x17..0x19 pool swaps) |
explorer:address:<mx_lower> | <Mx...> | Two event kinds: { "kind": "transaction", "height": "...", "transaction": txCard } and { "kind": "balances", "address": "Mx...", "height": "...", "current_wallet": {...}, "liquid_balances": {...} } |
| None | stake, commissions | Staking transactions and UpdateCommissionsEvent notifications |
Centrifugo v6 JSON wire frames
Frames are newline-delimited JSON commands (\n). After opening the socket, send connect followed by subscribe commands. Reply {}\n whenever the broker sends an empty {} ping frame (every 25 s).
Sample explorer:blocks push frame:
{
"push": {
"channel": "explorer:blocks",
"pub": {
"offset": 1042,
"data": {
"block": {
"height": "40893715",
"hash": "375349d74f84738d3accb2c88b8de9c83d1381966e80c8fef214aa56ba175ec0",
"time": "2026-11-15T23:06:02Z",
"tx_count": "3",
"block_reward": "103",
"proposer": {
"public_key": "Mpeeb140d1d932146cf394f868ac64467a2935c3f7d0ddd1517a954aa3fd2a7b04",
"moniker": "Sentinel Validator"
}
},
"totals": {
"latest_block_height": "40893715",
"total_transactions": "130482910"
}
}
}
}
}Sample explorer:address:<mx_lower> push frame wrapping txCard under transaction:
{
"push": {
"channel": "explorer:address:mx9858effd232b4033e47d90003d41ec34ecaeda94",
"pub": {
"offset": 88,
"data": {
"kind": "transaction",
"height": "40893715",
"transaction": {
"hash": "Mte53eeda7a4268983a7ea5481cf150ae9d6ef76c1e497f7489d99805a812b7011",
"height": "40893715",
"type": 1,
"code": "0",
"status": "success",
"from_address": "Mx6fac4d18c912343bf86fa7049364dd4e424ab9c0",
"payload": "INV-2026-8841",
"data": {
"coin": { "id": "1993", "symbol": "USDTE" },
"to": "Mx9858effd232b4033e47d90003d41ec34ecaeda94",
"value_pip": "25000000000000000000"
}
}
}
}
}
}Stream recovery (recover: true) and cursor HTTP catchup
Because explorer:address:<mx_lower> emits both incoming and outgoing wallet activity, payment handlers must check txCard.code ("0" or 0), Send type (1), (txCard.data?.to ?? "").toLowerCase() === MERCHANT_MX.toLowerCase(), numeric coin.id, and replay deduplication on txCard.hash.
To recover cleanly across disconnects:
- Persist
epoch, the latest channeloffset, andlastHeight. - Re-subscribe with
recover: true,offset, andepoch. When the outage fits inside20messages and300 s, Centrifugo setsrecovered: trueand replays missedpublications[]. - When
recovered === false(ring evicted or broker restarted with a newepoch), walkGET /api/v2/addresses/{address}?limit=50&cursor=...page by page until transaction height reaches<= lastHeight.
import { parsePip } from "@minter-network/tx-core";
const WS_URL =
process.env.MINTER_WS_URL ?? "wss://explorer.minter.network/connection/websocket";
const EXPLORER_API =
process.env.MINTER_EXPLORER_API_URL ?? "https://api-v2.minter.network/api/v2";
const MERCHANT_MX = "Mx9858effd232b4033e47d90003d41ec34ecaeda94";
const CHANNEL = `explorer:address:${MERCHANT_MX.toLowerCase()}`;
interface StreamCursorState {
epoch?: string;
offset?: number;
lastHeight: bigint;
}
interface TxCard {
hash: string;
height: string | number;
type: string | number;
code?: string | number | null;
status?: string;
payload?: string;
data?: {
to?: string;
value_pip?: string;
coin?: { id?: string | number };
};
}
const state: StreamCursorState = { lastHeight: 0n };
const creditedHashes = new Set<string>();
const consumedInvoiceIds = new Set<string>();
function processPaymentCard(txCard: TxCard, openInvoices: Map<string, bigint>): void {
if (!txCard?.hash) return;
const hashKey = `mt${txCard.hash.trim().replace(/^(mt|0x)/i, "").toLowerCase()}`;
if (creditedHashes.has(hashKey)) return;
const codeOk =
txCard.code !== undefined &&
txCard.code !== null &&
String(txCard.code) === "0" &&
txCard.status !== "failed";
const isSend = Number(txCard.type) === 1;
const toOk = (txCard.data?.to ?? "").toLowerCase() === MERCHANT_MX.toLowerCase();
const coinOk = Number(txCard.data?.coin?.id) === 1993;
const invoiceId = (txCard.payload ?? "").trim();
const expectedPip = openInvoices.get(invoiceId);
if (
!codeOk ||
!isSend ||
!toOk ||
!coinOk ||
!txCard.data?.value_pip ||
expectedPip === undefined ||
consumedInvoiceIds.has(invoiceId)
) {
return;
}
if (BigInt(txCard.data.value_pip) >= expectedPip) {
creditedHashes.add(hashKey);
consumedInvoiceIds.add(invoiceId);
console.log("Credited USDTE invoice:", invoiceId, "tx:", txCard.hash);
}
}
async function catchUpViaHttpCursor(
sinceHeight: bigint,
openInvoices: Map<string, bigint>,
): Promise<void> {
let cursor: string | undefined;
while (true) {
const qs = new URLSearchParams({ limit: "50" });
if (cursor) qs.set("cursor", cursor);
const res = await fetch(`${EXPLORER_API}/addresses/${MERCHANT_MX}?${qs}`);
if (!res.ok) throw new Error(`Backfill HTTP ${res.status}`);
const body = (await res.json()) as {
data?: { transactions?: TxCard[]; next_cursor?: string | null };
};
const items = body.data?.transactions ?? [];
if (items.length === 0) break;
let reachedSavedHeight = false;
for (const txCard of items) {
const h = BigInt(txCard.height);
if (h <= sinceHeight) {
reachedSavedHeight = true;
break;
}
processPaymentCard(txCard, openInvoices);
}
if (reachedSavedHeight || !body.data?.next_cursor) break;
cursor = body.data.next_cursor;
}
}
export function startMerchantStream(
openInvoices = new Map<string, bigint>([["invoice:2026-9001", parsePip("25")]]),
): WebSocket {
const ws = new WebSocket(WS_URL);
ws.addEventListener("open", () => {
const sub: Record<string, unknown> = { channel: CHANNEL, recover: true };
if (state.epoch !== undefined && state.offset !== undefined) {
sub.epoch = state.epoch;
sub.offset = state.offset;
}
ws.send(
`${JSON.stringify({ id: 1, connect: {} })}\n${JSON.stringify({ id: 2, subscribe: sub })}\n`,
);
});
ws.addEventListener("message", (event) => {
for (const line of String(event.data).split("\n")) {
const trimmed = line.trim();
if (!trimmed) continue;
if (trimmed === "{}") {
ws.send("{}\n");
continue;
}
const msg = JSON.parse(trimmed) as {
id?: number;
subscribe?: {
epoch?: string;
offset?: number;
recovered?: boolean;
publications?: Array<{ offset?: number; data?: { kind?: string; height?: string; transaction?: TxCard } }>;
};
push?: {
channel?: string;
pub?: { offset?: number; data?: { kind?: string; height?: string; transaction?: TxCard } };
};
};
if (msg.id === 2 && msg.subscribe) {
const hadPriorPosition = state.epoch !== undefined;
state.epoch = msg.subscribe.epoch;
state.offset = msg.subscribe.offset;
for (const pub of msg.subscribe.publications ?? []) {
if (pub.offset !== undefined) state.offset = pub.offset;
if (pub.data?.kind === "transaction" && pub.data.transaction) {
processPaymentCard(pub.data.transaction, openInvoices);
const h = BigInt(pub.data.height ?? pub.data.transaction.height);
if (h > state.lastHeight) state.lastHeight = h;
}
}
if (hadPriorPosition && msg.subscribe.recovered === false && state.lastHeight > 0n) {
void catchUpViaHttpCursor(state.lastHeight, openInvoices);
}
}
const pub = msg.push?.pub;
if (msg.push?.channel === CHANNEL && pub) {
if (pub.offset !== undefined) state.offset = pub.offset;
if (pub.data?.kind === "transaction" && pub.data.transaction) {
processPaymentCard(pub.data.transaction, openInvoices);
const h = BigInt(pub.data.height ?? pub.data.transaction.height);
if (h > state.lastHeight) state.lastHeight = h;
}
}
}
});
return ws;
}Inspecting raw frames with websocat
Send newline-separated connect and subscribe frames from a terminal with websocat:
printf '{"id":1,"connect":{}}\n{"id":2,"subscribe":{"channel":"explorer:blocks"}}\n' | \
websocat wss://explorer.minter.network/connection/websocket