QubicTypeScript

subscribeQuTransfers

Subscribes to QU transfer events (log type 0) with fully decoded, type-narrowed payloads.

Signature

subscribeQuTransfers(
  bob: BobSubscriptionClient,
  filter?: Omit<EventFilter, 'logTypes'>,
  options?: SubOptions,
): AsyncIterable<SubscriptionEvent<TypedEvent & { logType: 0 }>>

Purpose

Subscribes to QU transfer events (log type 0). Each event is decoded and narrowed to TypedEvent & { logType: 0 }, giving you typed access to data.source, data.destination, and data.amount.

import { subscribeQuTransfers } from "@qubic.org/events"
import { createBobClient } from "@qubic.org/bob"
import { toIdentity } from "@qubic.org/types"

const bob = createBobClient({ baseUrl: "http://localhost:40420" })
const identity = toIdentity("CFBMEMZOIDEXQAUXYYSZIURADQLAPWPMNJXQSNVQZAHYVOPYUKKJBJUCTVJL")
const ac = new AbortController()

for await (const event of subscribeQuTransfers(
  bob.subscription,
  { identity },
  { signal: ac.signal },
)) {
  if (event.isCatchUp) continue

  const { source, destination, amount } = event.data.data
  const dir = source === identity ? "OUT" : "IN"
  console.log(`[tick ${event.data.tick}] [${dir}] ${amount}n QU`)
  console.log(`  ${source} -> ${destination}`)
}

Parameters

NameTypeDescription
bobBobSubscriptionClientSubscription client
filterOmit<EventFilter, 'logTypes'>Optional filter — identity, contract, tick range
options.startLogIdbigintResume from this log ID
options.startEpochnumberStart from the beginning of this epoch
options.signalAbortSignalStops the iteration when aborted

Returns

AsyncIterable<SubscriptionEvent<TypedEvent & { logType: 0 }>>event.data.data has source, destination, and amount.

Watching multiple identities

Each helper call creates an independent subscription. Run them in parallel with Promise.all.

import { toIdentity } from "@qubic.org/types"

const identities = [
  toIdentity("CFBMEMZOIDEXQAUXYYSZIURADQLAPWPMNJXQSNVQZAHYVOPYUKKJBJUCTVJL"),
  toIdentity("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJ"),
]

const ac = new AbortController()

async function watch(identity: ReturnType<typeof toIdentity>) {
  for await (const event of subscribeQuTransfers(
    bob.subscription,
    { identity },
    { signal: ac.signal },
  )) {
    if (event.isCatchUp) continue
    console.log(identity.slice(0, 8), event.data.data.amount)
  }
}

await Promise.all(identities.map(watch))

On this page