QubicTypeScript

useEventLogs

Fetches historical event logs from the archive API for a tick range or contract.

useEventLogs queries the archive API for events emitted by smart contracts. Filter by contract index, tick range, or both. Pass undefined as the request to skip the fetch.

useEventLogs(request, options?)

import { useEventLogs } from "@qubic.org/react"
import { QEARN_CONTRACT_INDEX } from "@qubic.org/contracts"

function QearnEvents({ fromTick, toTick }: { fromTick: number; toTick: number }) {
  const { data, isLoading, error } = useEventLogs({
    contractIndex: QEARN_CONTRACT_INDEX,
    fromTick,
    toTick,
  })

  if (isLoading) return <p>Loading events...</p>
  if (error) return <p>Error: {error.message}</p>

  return (
    <ul>
      {data?.map((event, i) => (
        <li key={i}>
          Tick {event.tick} — type {event.eventType}
        </li>
      ))}
    </ul>
  )
}

Parameters

NameTypeDescription
requestGetEventLogsRequest | undefinedQuery parameters. Pass undefined to skip the fetch.
request.contractIndexnumberFilter by contract index. Optional.
request.fromTicknumberStart of the tick range (inclusive). Optional.
request.toTicknumberEnd of the tick range (inclusive). Optional.
options.refetchIntervalnumber | falsePolling interval in milliseconds. Pass false to disable.

Returns

FieldTypeDescription
dataQueryEvent[] | undefinedList of matching events, or undefined while loading.
isLoadingbooleanTrue while the first fetch is in progress.
errorQubicRpcError | nullNetwork or parse error.

On this page