Skip to main content
useTxNormalizedEvents fetches normalized events for a given transaction ID. It does not use the context client; it creates its own client from the provided base URL or settings. Use it when you have a transaction hash and want loading/error state and refetch.

When to use

  • Anywhere (no AlphscanProvider required).
  • When you need normalized events for a single transaction with loading/error and refetch.

Signature

function useTxNormalizedEvents(
  transactionId: string | undefined,
  options?: UseTxNormalizedEventsOptions
): {
  data: TxNormalizedEventsResponse | null;
  loading: boolean;
  error: Error | null;
  refetch: () => Promise<void>;
}

UseTxNormalizedEventsOptions

OptionTypeDefaultDescription
baseUrlstring"https://api.alphscan.io"API base URL.
settingsPartial<AlphscanSettings>Full settings (overrides baseUrl).
enabledbooleantrueIf false, or transactionId falsy, no request.

Return value

FieldTypeDescription
dataTxNormalizedEventsResponse | null{ transaction_id, events } or null.
loadingbooleanRequest in progress.
errorError | nullError if request failed.
refetch() => Promise<void>Refetch events.

Example

import { useTxNormalizedEvents } from "@alphscan/sdk-react";

function TransactionEvents({ txId }: { txId: string | undefined }) {
  const { data, loading, error, refetch } = useTxNormalizedEvents(txId, {
    baseUrl: "https://api.alphscan.io",
    apiKey: process.env.NEXT_PUBLIC_ALPHSCAN_API_KEY,
    enabled: !!txId,
  });

  if (!txId) return <p>Enter a transaction ID</p>;
  if (loading) return <p>Loading events…</p>;
  if (error) return <p>Error: {error.message}</p>;
  if (!data) return null;

  return (
    <div>
      <p>Transaction {data.transaction_id}: {data.events.length} events</p>
      <ul>
        {data.events.map((e) => (
          <li key={e.id}>{e.category}{e.sub_kind}</li>
        ))}
      </ul>
      <button onClick={refetch}>Refetch</button>
    </div>
  );
}
To render events with the UI library, use @alphscan/sdk-react-ui (e.g. NormalizedEventsList).