> ## Documentation Index
> Fetch the complete documentation index at: https://docs.alphscan.io/llms.txt
> Use this file to discover all available pages before exploring further.

# useTxNormalizedEvents

> Transaction normalized events hook

**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

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

## UseTxNormalizedEventsOptions

| Option     | Type                        | Default                     | Description                                   |
| ---------- | --------------------------- | --------------------------- | --------------------------------------------- |
| `baseUrl`  | `string`                    | `"https://api.alphscan.io"` | API base URL.                                 |
| `settings` | `Partial<AlphscanSettings>` | —                           | Full settings (overrides baseUrl).            |
| `enabled`  | `boolean`                   | `true`                      | If false, or transactionId falsy, no request. |

## Return value

| Field     | Type                                 | Description                           |
| --------- | ------------------------------------ | ------------------------------------- |
| `data`    | `TxNormalizedEventsResponse \| null` | `{ transaction_id, events }` or null. |
| `loading` | `boolean`                            | Request in progress.                  |
| `error`   | `Error \| null`                      | Error if request failed.              |
| `refetch` | `() => Promise<void>`                | Refetch events.                       |

## Example

```tsx theme={null}
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`).
