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

# Client & settings

> Create the Alphscan client and configure API URL, key, and environment

## Creating the client

Use **`alphscan(settings?)`** to create the API client. Settings can be omitted (then env is used), or passed to override.

```typescript theme={null}
import { alphscan } from "@alphscan/sdk";

const client = alphscan();
// Uses process.env: ALPHSCAN_API_URL, ALPHSCAN_API_KEY, etc.

const clientWithOverrides = alphscan({
  apiUrl: "https://api.alphscan.io",
  apiKey: "sk_...",
  version: "dev",
});
```

## AlphscanSettings

| Field                | Type     | Description                                                               |
| -------------------- | -------- | ------------------------------------------------------------------------- |
| `apiUrl`             | `string` | API base URL (e.g. `https://api.alphscan.io`). No trailing slash.         |
| `version`            | `string` | Stage/version (e.g. `"dev"` \| `"prod"`). Appended to `apiUrl` when set.  |
| `apiKey`             | `string` | API key for authenticated requests (X-API-Key and Authorization: Bearer). |
| `alephiumNodeUrl`    | `string` | Alephium node URL.                                                        |
| `alephiumBackendUrl` | `string` | Alephium backend URL.                                                     |
| `explorerUrl`        | `string` | Block explorer base URL.                                                  |

## Environment variables

The SDK reads settings from the environment when you don't pass them:

| Env key                         | Maps to              |
| ------------------------------- | -------------------- |
| `ALPHSCAN_API_URL`              | `apiUrl`             |
| `ALPHSCAN_VERSION`              | `version`            |
| `ALPHSCAN_API_KEY`              | `apiKey`             |
| `ALPHIUM_NODE_URL`              | `alephiumNodeUrl`    |
| `ALPHSCAN_ALEPHIUM_BACKEND_URL` | `alephiumBackendUrl` |
| `ALPHSCAN_EXPLORER_URL`         | `explorerUrl`        |

### Helpers

```typescript theme={null}
import {
  getSettingsFromEnv,
  resolveSettings,
  getApiBaseUrl,
  ENV_KEYS,
  DEFAULT_ALPHIUM_NODE_URL,
  DEFAULT_EXPLORER_URL,
} from "@alphscan/sdk";

const fromEnv = getSettingsFromEnv();
const resolved = resolveSettings({ apiKey: "sk_..." });
const baseUrl = getApiBaseUrl(resolved);
```

* **`getSettingsFromEnv()`** — returns a partial `AlphscanSettings` from `process.env`.
* **`resolveSettings(overrides?)`** — merges env with overrides (overrides win).
* **`getApiBaseUrl(settings)`** — returns the effective base URL (e.g. `https://api.alphscan.io` or `https://api.alphscan.io/dev`).

## AlphscanClientApi

The object returned by `alphscan()`:

| Member                         | Type                                     | Description                                 |
| ------------------------------ | ---------------------------------------- | ------------------------------------------- |
| `tx(transactionId)`            | `(id: string) => TxApi`                  | Transaction-scoped API (normalized events). |
| `plan`                         | `PlanApi`                                | List plans (public).                        |
| `keys`                         | `KeysApi`                                | List/create keys (requires apiKey).         |
| `payment`                      | `PaymentApi`                             | Payment flow (requires apiKey).             |
| `token`                        | `TokenApi`                               | List tokens (public).                       |
| `request(method, path, body?)` | `<T>(method, path, body?) => Promise<T>` | Raw request.                                |

Accessing `keys` or `payment` without an API key throws.

## Deprecated

**`createAlphscanClient({ baseUrl })`** — use `alphscan({ apiUrl: baseUrl })` instead.
