QubicTypeScript

subscribeAssetEvents

Subscribes to all asset-related log types (issuance, ownership, and possession changes) with decoded payloads.

Signature

subscribeAssetEvents(
  bob: BobSubscriptionClient,
  filter?: Omit<EventFilter, 'logTypes'>,
  options?: SubOptions,
): AsyncIterable<SubscriptionEvent<TypedEvent>>

Purpose

Subscribes to all asset-related log types: issuance (1), ownership change (2), possession change (3), ownership managing contract change (11), and possession managing contract change (12). Switch on event.data.logType using LOG_TYPE constants to narrow to specific event shapes.

import { subscribeAssetEvents, LOG_TYPE } from "@qubic.org/events"
import { createBobClient } from "@qubic.org/bob"

const bob = createBobClient({ baseUrl: "http://localhost:40420" })

for await (const event of subscribeAssetEvents(bob.subscription, { identity })) {
  if (event.isCatchUp) continue

  const typed = event.data

  if (typed.logType === LOG_TYPE.ASSET_ISSUANCE) {
    console.log("New asset:", typed.data.assetName, "shares:", typed.data.numberOfShares)
  } else if (typed.logType === LOG_TYPE.ASSET_OWNERSHIP_CHANGE) {
    console.log(
      typed.data.assetName,
      "ownership:",
      typed.data.source,
      "->",
      typed.data.destination,
    )
  }
}

Parameters

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

Returns

AsyncIterable<SubscriptionEvent<TypedEvent>> — switch on event.data.logType to narrow to the specific asset event shape.

Covered log types

LOG_TYPE constantValueDescription
ASSET_ISSUANCE1New asset issued
ASSET_OWNERSHIP_CHANGE2Asset ownership transferred
ASSET_POSSESSION_CHANGE3Asset possession transferred
ASSET_OWNERSHIP_MANAGING_CONTRACT_CHANGE11Ownership managing contract updated
ASSET_POSSESSION_MANAGING_CONTRACT_CHANGE12Possession managing contract updated

On this page