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

# SDK structure

> The handful of patterns every part of the SDK follows: the ladder, namespaces, containers, hook state, and flows that return instead of throwing.

> [!TIP]
>
> **In a hurry?** Skip straight to [Set up OAuth authentication](https://docs.passage.coinlist.co/sdk/oauth-authentication.md) and come back when something surprises you. Nothing here is a prerequisite - this page is optional background.

The SDK follows a small set of consistent patterns. The five patterns below apply across the SDK.

## The same feature at three levels

Every feature is available at several levels. Here is one feature - listing offers - at all three:

```tsx theme={null}
// L3  Components. UI and behavior, working.
<OffersGridContainer onOfferClick={(offer) => router.push(`/offers/${offer.id}`)} />

// L2  Hooks. The behavior; you write the UI.
const { offersState } = useOffers();

// L1  Client. The logic; you write the state and the UI.
const offers = await passage.offers.list();

// Below L1 there is no SDK - call the HTTP API directly.
```

All three do the same work. They differ only in how much of it you take over. **Start at L3** and drop a rung when the one above cannot give you what you need.

Three things follow from this that are easy to miss:

* **You pick a rung per feature, not per application.** Rendering `<CheckoutContainer>` while driving `passage.offers.list()` yourself is normal, not a compromise. The rungs are built from each other, so mixing them cannot desynchronize anything.
* **A feature may stop at a rung, but never skips one.** A feature with a component always has the hooks and the namespace beneath it, so dropping a rung never leaves you without a way forward.
* **Each rung exposes its entry points, not its parts.** Per feature, the public surface is the root container (L3), the viewmodel behind it and the data hooks it is built from (L2), and the namespaces (L1). The views, steps and sub-screens a container composes are internal, so there is no supported way to render the SDK's markup over your own logic: take the container, or build your UI on the viewmodel and hooks.

> [!NOTE]
>
> L2 and L3 are browser-only, because a backend renders nothing. **L1 is the only level present everywhere**, which is why `passage.offers.list()` reads identically on your server and in your React tree. See [the grid in the quickstart](https://docs.passage.coinlist.co/sdk/quickstart.md#environment-where-code-runs).

## Namespaces

**The entire L1 surface is namespaces.** `passage.init()` is the only top-level member on the browser client, because it is lifecycle rather than domain; `PassageServer` has none at all. So every operation you will ever want is `passage.{something}.{verb}()`, and finding it means picking the right noun.

Two naming rules tell you which noun:

* **CoinList's own capabilities are named after what they do**: `auth`, `offers`, `requirements`, `wallets`, `erc20`, `tokenSale`, `tokens`, and the browser-only `support`.
* **A third party's namespace is named after the provider**: `superstate`, `ondo`, `centrifuge`. Not after what it does. A second provider ships its own swap, so `passage.swap` could only ever have meant one of them - which is exactly why it was renamed in v0.11.0.

Methods share one vocabulary, with the namespace's own noun dropped, so `offers.list()` rather than `offers.listOffers()`:

| Method | Meaning |
| - | - |
| `list()` | Every item, paginating for you |
| `listPage(params)` | One page, when you paginate yourself |
| `get(id)` | One item by id |
| `create*` / `submit*` / `remove*` | Writes |
| A real domain verb | Where one exists: `connect`, `connectExternal`, `allowWallet`, `execute` |

**Any method taking more than one argument takes a single params object.** The exception is the app-level token on `PassageServer`, an optional second argument to `offers.listPage`, `offers.get`, and `requirements.forOffer`. Most single-argument methods take the value directly. You never have to remember an argument order.

**Outside `passage.auth`, API-backed methods throw `NotAuthenticatedError` without a session they accept.** Most need a CoinList user, so a wallet sign-in session throws too: `passage.offers`, `passage.wallets` apart from the `connect` flow, `passage.tokenSale` apart from the `execute` flow, `passage.superstate.allowWallet`, and `passage.requirements` apart from `forOffer`. That means `useOffers` and `useOfferDetails` cannot load on a wallet session. The API-backed methods on `passage.ondo` and `passage.centrifuge`, and `requirements.forOffer`, also take a wallet session, which builds only for its own wallet and chain: CoinList answers `403` to any other. On `PassageServer`, `passage.offers` and `requirements.forOffer` also accept an app-level token from `auth.clientCredentials()`, which needs no session and is what reads offers for a wallet session. `passage.tokens` needs no session at all: it is public, reads a CDN, and works with a read-only server session store. On-chain reads (`passage.erc20`, the `passage.superstate` reads, and `passage.centrifuge.readDepositPosition` and `readRedeemPosition`) are not API-backed: they go through CoinList's JSON-RPC proxy by default, which fails a logged-out read with a viem-wrapped `401`, or through your own node via `Config.rpc`, which needs no session. On `PassageServer`, when the SDK cannot find out whether a session exists (the token refresh hit a 5xx or a network failure after the access token expired), these methods throw that underlying error instead of `NotAuthenticatedError`.

> [card] [Package overview](https://docs.passage.coinlist.co/sdks.md#namespaces)
>
> The full table of namespaces and their methods, for looking one up.

## Components

Every feature's component is a **container**: `CheckoutContainer`, `ClaimContainer`, `OffersGridContainer`, `RequirementsChecklistContainer`, `CoinListSignInCardContainer`. You hand it input and config, and it owns everything else. The only other components are a few presentational pieces you lay out yourself: `CoinListSignInButton`, `OfferAssetCard` and `OfferSaleCard`. `RequirementsChecklistView` is also still exported, as a loading placeholder, but is due to be removed, and `PassageStyleScope` is the styling wrapper every SDK component already puts around itself.

Three habits will keep you out of trouble:

* **Let the container decide for you.** `<CheckoutContainer>` routes on `offer.type` (and on its `side` prop for Ondo and Centrifuge), so a new provider is a version bump rather than your problem. The per-provider checkout containers are not exported. When you need your own UI for one provider, drop to L2 and render that product's viewmodel, such as `useOndoBuyCheckoutViewModel()`. For Ondo and Centrifuge, `CheckoutContainer` also holds the checkout back until the session is settled, which your own UI does with `useCheckoutSessionViewModel` (`@alpha`).
* **Optional `onX` callbacks are overrides, not wiring.** They default to something sensible - `RequirementsChecklistContainer`'s action button already calls `passage.requirements.handle`. Omit them until a default is wrong for you.
* **You never need a style provider.** Every exported component wraps its own output in a style scope, so it renders fully styled wherever you put it.

## Hooks

**State is a machine, not a pair of booleans.** Loading, error and content are one discriminated union with machine-readable `reason` codes:

```ts theme={null}
type LoadOffersState =
  | { type: "LOADING" }
  | { type: "ERROR"; reason: "not-authenticated" | "generic-error" }
  | { type: "CONTENT"; offers: Offer[] };
```

Switch on it exhaustively and assign the `default` branch to `const exhaustive: never = state`. A state added in a future release then becomes a compile error rather than a blank screen your users find first. The catalog hooks name the field after what it holds - `offersState`, `requirementsState`. Newer data hooks (`useErc20Balance`, `useSwapQuote`, the Ondo and Centrifuge hooks) return a plain `state`, and viewmodels return `{ state, onEvent }`, apart from `useCheckoutSessionViewModel`, which has no events and returns `{ state }`.

Two options recur, and both exist because of how React works rather than as conveniences:

* **`data` is how server rendering works.** Pass data your backend already fetched with `PassageServer` and the hook uses it as-is, skipping the initial client fetch. Where a `refetch()` exists it still goes to the network: the seed answers the first render only. [Worked example](https://docs.passage.coinlist.co/sdk/fetch-offers.md#server-side-pre-fetch).
* **`enabled` is how you turn a hook off.** React forbids calling a hook conditionally, so a hook you cannot skip must instead go quiet: `enabled: false` means no requests and no timers. Most hooks then report a `DISABLED` state, since no answer is coming. The catalog reads (`useOffers`, `useOfferDetails`, `useRequirements`) have no `DISABLED` arm and stay in `LOADING` unless they already hold data. `useOptionAddresses` reports an empty `CONTENT` (or its `data` seed) while disabled. `CheckoutContainer` takes `enabled` too and forwards it to the checkout it mounts, to pause one that is mounted but not on screen yet.

## Flows return, they don't throw

Anything that drives a wallet - `passage.superstate.execute`, `passage.ondo.prepareBuy`, `passage.tokenSale.execute`, `passage.centrifuge.buy`, `passage.centrifuge.sell`, `passage.wallets.connect` - is a **flow**, and a flow is **total**. It does not throw. It returns a result tagged with the step that failed:

```ts theme={null}
const result = await passage.tokenSale.execute(tokenSaleParams);

if (result.type === "success") {
  // result carries what the flow produced
} else {
  // result.error.step names exactly what went wrong,
  // and carries a typed WalletError cause where a wallet was involved
}
```

That is the difference to internalize: **wrap namespace calls in try/catch, and branch on a flow's result.** Every step is documented per provider, so you can write real copy for a rejected signature instead of one generic message. Most flows also report progress through `onProgress`, a callback of named phases, so you can tell a user which wallet popup they are looking at.

`passage.auth.signInWithWallet` is a flow too, with one exception: without the `walletSignIn` prop on `PassageProvider`, it throws `WalletSignInConfigRequiredError`.

Let your wallet library's own errors propagate out of your `EvmWallet` implementation. The SDK catches and classifies them into a typed `WalletError`, so you never parse a wallet error string. The one error to throw yourself is `WalletDisconnectedError`, from `@passage-cl/react/universal`, when a method is called after the wallet disconnected or the user switched accounts. The SDK then asks the user to reconnect rather than to retry. See [Wallets](https://docs.passage.coinlist.co/sdk/wallets.md) and [Disconnected wallets](https://docs.passage.coinlist.co/sdk/errors.md#disconnected-wallets).

## Next step

> [card] [Set up OAuth authentication](https://docs.passage.coinlist.co/sdk/oauth-authentication.md)
>
> Add `PassageProvider`, a sign-in surface, callback handling, and server routes.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.