Skip to main content

Creating the client

Use alphscan(settings?) to create the API client. Settings can be omitted (then env is used), or passed to override.
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

FieldTypeDescription
apiUrlstringAPI base URL (e.g. https://api.alphscan.io). No trailing slash.
versionstringStage/version (e.g. "dev" | "prod"). Appended to apiUrl when set.
apiKeystringAPI key for authenticated requests (X-API-Key and Authorization: Bearer).
alephiumNodeUrlstringAlephium node URL.
alephiumBackendUrlstringAlephium backend URL.
explorerUrlstringBlock explorer base URL.

Environment variables

The SDK reads settings from the environment when you don’t pass them:
Env keyMaps to
ALPHSCAN_API_URLapiUrl
ALPHSCAN_VERSIONversion
ALPHSCAN_API_KEYapiKey
ALPHIUM_NODE_URLalephiumNodeUrl
ALPHSCAN_ALEPHIUM_BACKEND_URLalephiumBackendUrl
ALPHSCAN_EXPLORER_URLexplorerUrl

Helpers

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():
MemberTypeDescription
tx(transactionId)(id: string) => TxApiTransaction-scoped API (normalized events).
planPlanApiList plans (public).
keysKeysApiList/create keys (requires apiKey).
paymentPaymentApiPayment flow (requires apiKey).
tokenTokenApiList 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.