QubicTypeScript

subscribeContractLogs

Subscribes to smart contract message log types (error, warning, information, debug) with decoded payloads.

Signature

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

Purpose

Subscribes to smart contract message log types: error (4), warning (5), information (6), and debug (7). Each event is decoded and provides contractIndex and contractMessageType on event.data.data.

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

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

for await (const event of subscribeContractLogs(bob.subscription, { contractIndex: 9 })) {
  if (event.isCatchUp) continue

  const typed = event.data

  if (typed.logType === LOG_TYPE.CONTRACT_ERROR_MESSAGE) {
    console.error(
      `Contract ${typed.data.contractIndex} error (type ${typed.data.contractMessageType})`
    )
  } else if (typed.logType === LOG_TYPE.CONTRACT_INFORMATION_MESSAGE) {
    console.log(
      `Contract ${typed.data.contractIndex} info (type ${typed.data.contractMessageType})`
    )
  }
}

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>>event.data.data has contractIndex and contractMessageType. Switch on event.data.logType to narrow to the specific message level.

Covered log types

LOG_TYPE constantValueDescription
CONTRACT_ERROR_MESSAGE4Contract emitted an error
CONTRACT_WARNING_MESSAGE5Contract emitted a warning
CONTRACT_INFORMATION_MESSAGE6Contract emitted an informational message
CONTRACT_DEBUG_MESSAGE7Contract emitted a debug message

On this page