Skip to main content

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

PropTypeDescription
apiUrlstringAPI base URL (e.g. https://api.alphscan.io). Trailing slashes are removed.
apiKeystringOptional API key. Empty string is treated as no key.
childrenReactNodeTree that can use useClient() and other hooks.

Example

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

function useClient(): AlphscanClientApi

Example

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.