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

# Building the Checkout flow

> Render CheckoutContainer with an offer, the option being bought, a chain and your wallets. It picks the right provider's flow for you.

`CheckoutContainer` is the **plug-and-play checkout**: hand it an offer and it renders whichever provider that offer belongs to. Superstate swap, Ondo buy, Ondo sell, CoinList token sale, Centrifuge deposit, Centrifuge redemption - you write one integration, not six.

This is the highest rung of the SDK (**L3, components**) and the one to start from. Reach for the hooks below it only when you need markup the SDK does not give you.

> [!NOTE]
>
> `CheckoutContainer` is the only checkout component the SDK exports. The per-provider containers it mounts are internal, so routing on `offer.type` is never your problem: when a new provider ships, `CheckoutContainer` renders it.

## Prerequisites

* A completed [OAuth](https://docs.passage.coinlist.co/sdk/oauth-authentication.md) session with a working `PassageProvider`
* An `OfferDetail` from [Display offer details](https://docs.passage.coinlist.co/sdk/sale-details.md). `useOfferDetails` needs a CoinList login, so on a [wallet session](#the-session-gate) read the offer on your server
* A [`CheckoutWalletSelection`](https://docs.passage.coinlist.co/sdk/wallets#checkoutwalletselection-what-checkout-takes) built from your wallet stack

## Render it

```tsx theme={null}
"use client";

import {
  CheckoutContainer,
  type CheckoutConfig,
  type CheckoutWalletSelection,
} from "@passage-cl/react";
import type {
  OfferDetail,
  OfferOptionId,
  OrderBookSide,
} from "@passage-cl/react/universal";

// Per-integration, not per-offer: build it once and pass the same object
// for every offer you render. Every key is optional.
const checkoutConfig: CheckoutConfig = {
  "ondo::swap": {
    onOrderConfirmed: (order) => {
      console.info("Ondo order mined", order.txHash);
    },
  },
};

export function Checkout({
  offer,
  optionId,
  wallets,
  side = "buy",
}: {
  offer: OfferDetail;
  // The option the user picked, whose requirements you showed them.
  optionId: OfferOptionId;
  wallets: CheckoutWalletSelection;
  side?: OrderBookSide;
}) {
  return (
    <CheckoutContainer
      key={`${offer.id}:ethereum_mainnet:${side}:${optionId}`}
      offer={offer}
      chain="ethereum_mainnet"
      side={side}
      optionId={optionId}
      wallets={wallets}
      config={checkoutConfig}
    />
  );
}
```

That is the whole integration. Only `offer`, `chain`, `optionId` and `wallets` are required: `<CheckoutContainer offer={offer} chain={chain} optionId={optionId} wallets={wallets} />` renders every provider on its defaults. [`optionId`](#optionid-which-option-is-bought) is required for every offer type, even one with a single option. The container is **self-scoped**: it renders fully styled with no style provider in the tree. In the dark theme it shows each token's dark logo when the token registry has one.

### Props

| Prop | Type | Required | Description |
| - | - | - | - |
| `offer` | `OfferDetail` | Yes | The offer being bought. Its `type` decides which provider renders. Fixed for the mount: remount to change it. |
| `chain` | `EthereumChain` | Yes | Where the order executes: balance reads, the approval, and the broadcast all go here. Fixed for the mount: remount to change it. |
| `wallets` | `CheckoutWalletSelection` | Yes | The wallets the buyer can spend from, your connector for an external one, and an optional `preselected` wallet. See [Wallets](https://docs.passage.coinlist.co/sdk/wallets.md) and [Wallets and the wallet step](#wallets-and-the-wallet-step). |
| `side` | `OrderBookSide` | No | Default `"buy"`. `"sell"` liquidates a holding instead of investing in it. Read once, at mount. See [`side`](#side-buy-or-sell). |
| `optionId` | `OfferOptionId` | Yes | Which of the offer's options is bought: the one whose requirements you showed the user. Required for every offer type. Superstate and a Centrifuge redemption ignore it. The flow reads it once, at mount. See [`optionId`](#optionid-which-option-is-bought). |
| `config` | `CheckoutConfig` | No | Default `{}`. Per-provider callbacks, keyed by offer type. See [CheckoutConfig](#checkoutconfig). |
| `enabled` | `boolean` | No | Default `true`. `false` turns off every request and timer in the mounted provider, for a checkout that is mounted but not on screen yet. |
| `className` | `string` | No | Applied to the rendered provider view, and to the [session gate's](#the-session-gate) skeleton and cards. |

## One mount, one offer, one chain

**To render a different offer, chain, side, option or preselected wallet, remount rather than reassign.** Give the container a `key` that changes with them, as the example above does. Add `wallets.preselected?.address` to the key if your preselection can change on one page.

`offer`, `chain`, `side`, `optionId` and `wallets.preselected` are read as fixed for the lifetime of the mount. Each provider's viewmodel owns a step machine - which wallet was authorized, how much is being spent - and that progress is bound to the order it was made against: a Superstate wallet authorization is allowlisted per offer, and an ERC-20 approval is granted per chain, for one specific token. Changing any of them in place would carry a completed step onto an order it was never made for. Worse, a swap could land mid-execution, between an approval and the broadcast it was granted for. So the flow reads `side`, `optionId`, and `wallets.preselected` once and ignores later values. `offer` and `chain` are not latched, so changing either in place is unsupported. The [session gate](#the-session-gate) above the flow reads `optionId` on every render, so change the option through `key` on a wallet session too.

The rest of `wallets` stays live. A newly connected external wallet appears as a row without a remount, and a wallet you stop supplying sends the checkout back to its wallet step (see [When the wallet disconnects](#when-the-wallet-disconnects)).

React discards the old flow's state along with its component instance, which is the only reset that cannot strand an in-flight transaction.

## `side`: buy or sell

`side` is a prop rather than something the offer says, because no offer can answer it: `offer.type` is `ondo::swap` in both directions, and the direction is a property of your page rather than of the catalog. It is a prop rather than a config entry because it is per-*render*, while the config is per-integration, so one config object serves a buy page and a sell page.

| Offer type | `"buy"` (default) | `"sell"` |
| - | - | - |
| `ondo::swap` | The Ondo buy checkout | The Ondo sell checkout |
| `centrifuge::vault` | The vault deposit checkout | The vault redemption checkout |
| `superstate::swap`, `coinlist::token_sale` | Ignored: one direction only | Ignored |

A Centrifuge redemption is a request, not a sale. The user enters how many of the vault's shares to redeem, bounded only by what the wallet holds: the offer's dollar minimum applies to deposits only. The review approves the vault for that many shares, unless the allowance already covers them, and broadcasts the request. Placing it pays nothing yet. The fund fulfills the request later, and the user then claims the payout in a second transaction, for example with `ClaimContainer`. A vault pays in the same coin a deposit spends: USDZ, a test stablecoin, on `ethereum_sepolia`, and USDC on every other chain. A deposit works the same way in the other direction: the user claims the shares once the fund fulfills it. See [Centrifuge Vaults](https://docs.passage.coinlist.co/sdk/centrifuge-vaults.md).

> [!WARNING]
>
> **`side` is read once, at mount.** The flow below it holds an approval granted for whichever coin that side spends, so a re-render with a new `side` is ignored by design. A buy/sell toggle on one page works only if `side` is in the container's `key`. A forgotten `side` on a sell page renders the buy checkout.

Unmounting a checkout does not cancel an order already in flight. A Superstate swap, an Ondo swap or a token-sale order still goes through, and your `onOrderConfirmed` or `onOrderPlaced` callback still fires for it. A Centrifuge checkout unmounted while its approval mines (a deposit approves when the user confirms the amount, a redemption when they place it) broadcasts no request: the approval stays on-chain, no order is placed, and `onOrderPlaced` does not fire. Gate a toggle where it can reach an executing flow, for example by disabling it once the user is past the amount step.

## `optionId`: which option is bought

An offer lists one or more options in `offer.options`, and each option has its own requirements and minimum purchase. `optionId` names the option the user buys. Pass the option whose requirements you showed the user.

`optionId` is required for every offer type, even an offer with one option, and even for the providers that ignore it. The SDK never picks an option for you: a default would break silently the day the offer gains a second option. If your page selects an option automatically, pick it yourself, for example `offer.options[0]`, and pass its `id`.

| Offer type | What `optionId` does |
| - | - |
| `ondo::swap` (both sides), `centrifuge::vault` deposit | The order sends that option's id, so frontline runs that option's requirements. An Ondo buy and a Centrifuge deposit check the amount against that option's minimum. An Ondo sell has no minimum. |
| `coinlist::token_sale` | The checkout buys that option, at its price and minimum. |
| `superstate::swap`, `centrifuge::vault` redemption | Ignored. You still pass it. |

> [!WARNING]
>
> **Breaking in v0.16.0.** `optionId` used to be optional: Ondo and a Centrifuge deposit took the offer's only option, and a token sale bought its first one. Code that leaves it out no longer compiles. Pass the option the user picked.

When `optionId` names no option the offer shows, the checkout is blocked with `unknown-option`, so an offer with no options always blocks. A Superstate swap and a Centrifuge redemption never block on it. The checkout then shows a "not available" screen in place of its steps and sends no request, so the user never pays gas for an approval on an order that cannot go through. If you set a `logger`, the SDK logs `checkout blocked` at `error` level, with the reason, the offer's id and type, and the chain.

Like `side`, `optionId` is read once, at mount. If the user can switch options on one page, put `optionId` in the container's `key`, as in `${offer.id}:${chain}:${side}:${optionId}`.

## Wallets and the wallet step

`wallets` is a [`CheckoutWalletSelection`](https://docs.passage.coinlist.co/sdk/wallets#checkoutwalletselection-what-checkout-takes): `embedded`, `external`, an `externalAdapter` with `connect` and `disconnect`, and `preselected`. Set `externalAdapter` to `null` for a host with embedded wallets only. The external-wallet row is then hidden, unless `external` holds a connected wallet: that wallet still shows, with no way to disconnect it.

Every checkout runs the same three steps - wallet, amount, review - and every provider honors `wallets.preselected`:

| Provider | With `preselected` set |
| - | - |
| Ondo buy, Ondo sell, Centrifuge buy, Centrifuge sell, CoinList token sale | The wallet step is skipped. The flow opens on the amount, and the two remaining cards are numbered 1 and 2. After an order, the flow resets to the amount step. |
| Superstate | The wallet step stays, because it allowlists the wallet on-chain. It opens with the preselected wallet's row already selected. A wallet that matches no row (in neither `embedded` nor `external`) selects nothing. |

On a wallet session, the [session gate](#the-session-gate) replaces `preselected` for Ondo and Centrifuge with the session's wallet.

### When the wallet disconnects

The checkout holds the wallet the user confirmed by its **address**, not by the `EvmWallet` object. On every render it looks that address up again in the current `wallets` (case-insensitively, as [`WalletSelection.find`](https://docs.passage.coinlist.co/sdk/wallets#checkoutwalletselection-what-checkout-takes) does). So when your wallet stack hands over a fresh `EvmWallet` for the same address, for example after a chain switch, the checkout sends through the new one on its next request. You do not remount.

When you stop supplying a wallet at that address, because it disconnected or the external wallet moved to another account, the checkout reacts in one of two ways:

| Flow | What happens |
| - | - |
| Opened on the wallet step (no `preselected`, and always for Superstate) | The checkout returns to the wallet step and shows "Your wallet disconnected - reconnect or choose another." The amount and review are discarded. It waits while a step is sending through the wallet or holds an order that may still mine, so the user sees that outcome first. |
| Opened on the amount (`preselected` skipped the wallet step) | There is no wallet step to return to, so the checkout keeps the wallet it had. It also looks for that address in the current `preselected`, so a fresh preselected `EvmWallet` at the same address is picked up. If the wallet is gone, the next send fails and shows the same disconnected message. |

A send that fails because the wallet is gone classifies as the `disconnected` [`WalletError`](https://docs.passage.coinlist.co/sdk/wallets#let-wallet-errors-propagate), and every checkout shows the disconnected message for it rather than "try again". Your `EvmWallet` reports a disconnect by throwing `WalletDisconnectedError`, or by letting an EIP-1193 `4100` or wagmi's `ConnectorNotConnectedError` propagate.

On a wallet session, the [session gate](#the-session-gate) acts first. When `wallets.external` stops being the session's wallet, the gate replaces an Ondo or Centrifuge checkout with the "Connect your wallet" card. With `walletSignIn` set, the wallet change also ends the session, and the checkout then renders as for no session.

## The session gate

Ondo and Centrifuge checkouts wait for the session before they open. `CheckoutContainer` shows a skeleton until `PassageProvider` is ready, for every integration, whether or not you use wallet sign-in.

A **wallet session** belongs to a user who signed in with their wallet (`PassageProvider`'s `walletSignIn` prop) and has no CoinList login. Once the session is known, the first row that matches decides what renders:

| Session | What renders |
| - | - |
| Signed out, a CoinList login, or a session that failed to load | The checkout, with `wallets` as you passed them. |
| Wallet session on another chain than `chain` | The skeleton while the SDK signs the session out, then the checkout as for no session. |
| Wallet session, and the option has any requirement | A card: "Sign in to continue", "This offer needs a CoinList account." |
| Wallet session, and `wallets.external` is `null` or another address | A card: "Connect your wallet", "You signed in with `0x1234…cdef`. Connect it to trade this offer." |
| Any other wallet session | The checkout, paying from `wallets.external` with no wallet step, whatever `wallets.preselected` says. |

* **The cards have no button.** Your page renders the way to sign in or connect.
* **Any requirement asks for a CoinList login,** not only `coinlist_account`. The gate reads the option's requirements with the skeleton up. If the read fails, or `enabled` is `false`, the gate skips this check, and CoinList refuses an order the session cannot place. The wallet row still applies. A Centrifuge redemption passes no option, so it runs no check.
* **A new wallet session remounts the checkout,** and its progress goes with it. You do not add the session to `key`. Signing in with CoinList does not remount it.
* **`enabled={false}` reads nothing and signs nobody out,** and it keeps an opened checkout as it was.

Superstate and the token sale do not go through the gate. A wallet session cannot allowlist a wallet for Superstate or record a token-sale participation, because both need a CoinList login. A token sale asks for its approval first, so that transaction still goes out.

## CheckoutConfig

`CheckoutConfig` is keyed by `OfferType`, and **every key is optional**, as is the `config` prop itself. A provider you say nothing about runs on its defaults.

Nothing in the config is per-offer. It is per-*integration*, so you build one object and pass the same one for every offer you render. Anything the SDK can derive from the offer, it derives: Ondo's API symbol comes from `offer.asset.code`, and a token sale's funding contract, coins and price come off the offer.

| Key | Field | What you supply |
| - | - | - |
| `ondo::swap` | `onOrderConfirmed?: (order: OndoOrderPlaced) => void` | Optional. Fired once an Ondo swap has mined, either direction. The confirmation dialog shows regardless. |
| `superstate::swap` | `onOrderConfirmed?: (order: SuperstateOrderPlaced) => void` | Optional. Fired once a Superstate swap has mined. Superstate needs nothing else: the swap contract is looked up from the chain, and the funding assets are the provider's own constants. |
| `coinlist::token_sale` | `onOrderPlaced?: (order: TokenSaleOrderPlaced) => void` | Optional, `@alpha`. Fired once the participation is recorded. The order dialog shows either way. |
| `centrifuge::vault` | `onOrderPlaced?: (order: CentrifugeOrderPlaced) => void` | Optional, `@alpha`. Fired once a deposit or redemption request has mined. `order.side` (`"buy"` or `"sell"`) says which. The dialog shows either way. |

Use the callbacks to navigate, refresh a portfolio or log. The SDK already shows the confirmation.

## Token sales

`coinlist::token_sale` offers mount the SDK's own token-sale checkout: pick a wallet, enter an amount in USD paid in one of the stablecoins the sale accepts on `chain`, then review and place the order through `passage.tokenSale.execute`. The amount is checked against the option's minimum, and the amount and review steps are blocked outside the sale window.

`optionId` chooses which option is bought (see [`optionId`](#optionid-which-option-is-bought)). Some offers cannot take an order at all, and the checkout renders a "not available" screen in their place:

| Reason | When |
| - | - |
| `unsupported-chain` | The sale names no funding contract on `chain`. |
| `unknown-option` | `optionId` is not one of the offer's options. On a supported chain, an offer with no options always gets it. |
| `no-price` | The option has no fixed price, such as an auction. |
| `no-payable-asset` | The sale accepts no coin the SDK can pay with on `chain`. |

Each of these reasons sends no request and, if you set a `logger`, logs `checkout blocked` at `error` level.

## What happens underneath

`CheckoutContainer` switches on `offer.type` and mounts only the matching provider's container, handing it the offer narrowed to its variant. Ondo and Centrifuge mount theirs once the [session gate](#the-session-gate) opens. Only that provider's viewmodel runs, so the others fetch nothing and hold no timers. `enabled` is forwarded to the mounted container as-is: it pauses a checkout that is mounted but not on screen yet.

The `switch` on `offer.type` is exhaustive, and its `default` branch assigns to `const exhaustive: never`, so a new offer type is a compile error inside the SDK until it has a branch.

> [accordion] Build your own UI with hooks (L2)
>
> Each product exposes a **god viewmodel** wrapping its entire flow, plus the data hooks it is built from. Call one behind your own markup when you want the SDK's logic, state and error handling but not its UI.
>
> ```tsx theme={null}
> import {
>   type CheckoutWalletSelection,
>   useOndoBuyCheckoutViewModel,
> } from "@passage-cl/react";
> import type {
>   OfferOptionId,
>   OndoSwapOfferDetail,
> } from "@passage-cl/react/universal";
>
> export function MyOndoBuyCheckout({
>   offer,
>   optionId,
>   wallets,
> }: {
>   offer: OndoSwapOfferDetail;
>   optionId: OfferOptionId;
>   wallets: CheckoutWalletSelection;
> }) {
>   const { state, onEvent } = useOndoBuyCheckoutViewModel({
>     offer,
>     chain: "ethereum_mainnet",
>     optionId,
>     wallets,
>   });
>
>   // Render your own markup from `state`, and send user actions to `onEvent`.
>   return null;
> }
> ```
>
> | Viewmodel | `offer` | Takes `optionId` (required) |
> | - | - | - |
> | `useOndoBuyCheckoutViewModel`, `useOndoSellCheckoutViewModel` | `OndoSwapOfferDetail` | Yes |
> | `useSuperstateSwapCheckoutViewModel` | `SuperstateSwapOfferDetail` | No |
> | `useCoinListTokenSaleCheckoutViewModel` (`@alpha`) | `CoinListTokenSaleOfferDetail` | Yes |
> | `useCentrifugeBuyCheckoutViewModel` (`@alpha`) | `CentrifugeVaultOfferDetail` | Yes |
> | `useCentrifugeSellCheckoutViewModel` (`@alpha`) | `CentrifugeVaultOfferDetail` | No |
>
> Each takes `offer`, `chain`, `wallets`, `enabled?` and its provider's callback (`onOrderConfirmed` or `onOrderPlaced`), plus a required `optionId` where the table says so, and returns `{ state, onEvent }`. `optionId` works as it does on [`CheckoutContainer`](#optionid-which-option-is-bought): the viewmodel never picks an option, and an id the offer does not show blocks the flow with `unknown-option`. `state` is a discriminated union you `switch` on exhaustively, with a flow-level `error` arm for an offer that has no checkout to render, such as one that cannot settle on the chain you passed or one with no option to order. In the `content` arm of every flow except Superstate, `wallet` is `null` exactly when `preselected` skipped the wallet step.
>
> `CheckoutBlockedReason` gained `unknown-option` in v0.15.0, so `OndoCheckoutErrorReason` and `CentrifugeCheckoutErrorReason` gained it too. An exhaustive `switch` on either needs a case for it.
>
> The step components and step viewmodels are not exported. A god viewmodel is the smallest unit of the SDK's checkout logic you can call.
>
> If you call these directly you are routing on `offer.type` yourself. Narrow the offer and call each viewmodel inside its own component, so only the matching one is mounted. That routing is exactly what `CheckoutContainer` does for you.
>
> You also leave the [session gate](#the-session-gate) behind. To keep it for Ondo and Centrifuge, call `useCheckoutSessionViewModel({ offer, optionId, chain, wallets })` (`@alpha`), leaving out `optionId` for a Centrifuge redemption. While your UI is paused, pass `enabled: false`, or it still reads requirements and signs out a session on another chain. Its `state.type` is `loading`, `not-authenticated`, `wallet-missing`, or `open`. Mount your viewmodel once it is `open`, pass it `state.wallets`, and put `state.session` in its `key`.
>
> ```tsx theme={null}
> import { useCheckoutSessionViewModel } from "@passage-cl/react";
>
> export function MyGatedOndoBuy() {
>   const { state } = useCheckoutSessionViewModel({
>     offer,
>     optionId,
>     chain: "ethereum_mainnet",
>     wallets,
>   });
>
>   switch (state.type) {
>     case "loading":
>       return <p>Loading...</p>;
>     case "not-authenticated":
>       return <p>This offer needs a CoinList account.</p>;
>     case "wallet-missing":
>       return <p>Connect {state.wallet} to trade this offer.</p>;
>     case "open":
>       return (
>         <MyOndoBuyCheckout
>           key={state.session ?? "no-wallet-session"}
>           offer={offer}
>           optionId={optionId}
>           wallets={state.wallets}
>         />
>       );
>     default: {
>       const exhaustive: never = state;
>       return exhaustive;
>     }
>   }
> }
> ```
>
> Per-provider detail: [Superstate Swap](https://docs.passage.coinlist.co/sdk/swap-flow.md), [Ondo Swap](https://docs.passage.coinlist.co/sdk/ondo-swap.md), [Centrifuge Vaults](https://docs.passage.coinlist.co/sdk/centrifuge-vaults.md), [CoinList Token Sale](https://docs.passage.coinlist.co/sdk/invest-flow.md). The conventions the hooks share - `enabled`, `data`, and the shape of `state` - are in [SDK structure](https://docs.passage.coinlist.co/sdk/structure.md#hooks).

> [accordion] Drive it yourself with the client (L1)
>
> Below the hooks are plain TypeScript namespaces on `PassageClient`, with no React and no state. Use them for a non-React app, a custom state layer, or a step the SDK's flows do not cover.
>
> ```ts theme={null}
> const { passage } = usePassage();
>
> // Ondo: approve, then commit a firm quote, then broadcast it.
> // prepareBuy spends the funding coin; prepareSell delivers the asset.
> // Both take the offer option's id as offerOptionId.
> const prepared = await passage.ondo.prepareBuy(buyParams);
> const filled = await passage.ondo.executeSwap(swapParams);
>
> // Superstate: prove the wallet, then swap.
> await passage.superstate.authorizeWallet(authorizeParams);
> await passage.superstate.execute(superstateSwapParams);
>
> // CoinList token sale: approve and record a participation.
> await passage.tokenSale.execute(tokenSaleParams);
>
> // Centrifuge: approve, build and broadcast a request. buy approves the
> // vault's funding coin (USDZ on ethereum_sepolia, USDC elsewhere) and
> // takes offerOptionId; sell approves the vault's share token. The fund
> // fulfills the request later, and passage.centrifuge.claim collects the
> // result.
> await passage.centrifuge.buy(depositParams);
> await passage.centrifuge.sell(redeemParams);
> ```
>
> These return **step-tagged results rather than throwing**, so you can map each failure to your own copy. The full parameters, progress phases and error steps live on each provider's page.
>
> A wallet session can build Ondo and Centrifuge orders only for its own wallet and chain, and CoinList refuses any other. Allowlisting a wallet with `superstate.authorizeWallet` and recording a participation with `tokenSale.execute` need a CoinList login.

## Next steps

> [card] [Superstate Swap](https://docs.passage.coinlist.co/sdk/swap-flow.md)
>
> Wallet allowlisting, live quotes, and what Superstate needs from you.

> [card] [Ondo Swap](https://docs.passage.coinlist.co/sdk/ondo-swap.md)
>
> Both directions, what each one approves, and the two-call order.

> [card] [CoinList Token Sale](https://docs.passage.coinlist.co/sdk/invest-flow.md)
>
> The approval, the participation, and tracking participations.

> [card] [Errors and edge cases](https://docs.passage.coinlist.co/sdk/errors.md)
>
> Every error shape the flows return, and how to handle it.


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