> ## 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.

# Provider & useClient

> AlphscanProvider and useClient() hook

## AlphscanProvider

Wrap your app (or the part that needs the API) with **AlphscanProvider** so that **useClient()** can return the SDK client. The provider creates one client per apiUrl + apiKey and memoizes it.

### Props

| Prop     | Type      | Description                                                                                           |
| -------- | --------- | ----------------------------------------------------------------------------------------------------- |
| apiUrl   | string    | API base URL (e.g. [https://api.alphscan.io](https://api.alphscan.io)). Trailing slashes are removed. |
| apiKey   | string    | Optional API key. Empty string is treated as no key.                                                  |
| children | ReactNode | Tree that can use useClient() and other hooks.                                                        |

### Example

```tsx theme={null}
import { AlphscanProvider } from "@alphscan/sdk-react";

function App() {
  const apiUrl = process.env.NEXT_PUBLIC_ALPHSCAN_API_BASE_URL ?? "https://api.alphscan.io";
  const apiKey = "";

  return (
    <AlphscanProvider apiUrl={apiUrl} apiKey={apiKey}>
      <YourRoutes />
    </AlphscanProvider>
  );
}
```

## useClient()

Returns the AlphscanClientApi. Must be used inside AlphscanProvider; otherwise it throws.

### Signature

```typescript theme={null}
function useClient(): AlphscanClientApi
```

### Example

```tsx theme={null}
import { useClient } from "@alphscan/sdk-react";

function MyComponent() {
  const client = useClient();
  const handleFetch = async () => {
    const { tokens } = await client.token.list({ page: 1, pageSize: 10 });
    const { plans } = await client.plan.list();
  };
  return <button onClick={handleFetch}>Fetch</button>;
}
```

Use useClient() when you need the client for one-off calls. For tokens use useTokens; for transaction events use useTxNormalizedEvents.
