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

# Wallets: the EvmWallet seam

> Implement EvmWallet once and every Passage on-chain flow works with your wallet stack. Prove ownership, allowlist addresses, and hand wallets to CheckoutContainer.

The SDK ships **no wallet stack**. It is not coupled to Privy, Turnkey, AppKit, wagmi, or anything else, and it never connects a wallet itself. Wallet discovery, connection, and disconnection are your app's job.

That is deliberate. A partner may be a wallet provider themselves, and every partner already has a wallet story before they reach Passage. So the SDK inverts it: you implement one small interface, `EvmWallet`, and the SDK drives it. Do that once and every on-chain flow works - Superstate swaps, Ondo buys and sells, Centrifuge investments, redemptions and claims, token-sale approvals, ownership proofs.

Using an embedded wallet provider? See [Wallet partners](https://docs.passage.coinlist.co/wallet-partners) for providers with a documented Passage integration.

> [!NOTE]
>
> The SDK uses and ships [viem](https://viem.sh/) types, the de-facto TypeScript standard for Ethereum, so the interface lines up with whatever you are already using. A `SolanaWallet` seam will follow the same shape when Solana lands.

## Two shapes, one seam

There are two interfaces, and the smaller one is a subset of the larger.

| Interface | Members | Needed for |
| - | - | - |
| `EvmSigner` | `address`, `signMessage` | Proving wallet ownership, and wallet sign-in. No gas, no transaction. |
| `EvmWallet` | the two above, plus `writeContract`, `broadcastRawTx`, `awaitTx` | Everything on-chain: approvals, swaps, allowlist transactions. |

`EvmWallet extends EvmSigner`, so implementing the full interface satisfies both. If all you need is the requirements checklist binding a wallet to an offer option, a signer is enough and your users never see a gas prompt. Those entry points take a `ConnectWallet`, which is an `EvmSigner` plus the `chain` the signature is proven on (`EvmSigner & { readonly chain: EthereumChain }`).

All of these types come from `@passage-cl/react/universal`. Since v0.13.0 the root entry point no longer re-exports them.

## Implement EvmWallet

```ts theme={null}
import type { EvmWallet } from "@passage-cl/react/universal";
```

| Member | Signature | What the SDK does with it |
| - | - | - |
| `address` | `EvmWalletAddress` | Reads balances and allowances, and names the sender. |
| `signMessage` | `(message: string) => Promise<Hex>` | Ownership challenges, allowlist authorization, and wallet sign-in. |
| `writeContract` | `(params: WriteContractParams) => Promise<Hash>` | ERC-20 `approve`, and any contract call the SDK encodes itself. |
| `broadcastRawTx` | `(params: BroadcastTxParams) => Promise<Hash>` | Sends backend-encoded calldata **verbatim**. Never re-encode it: the contract verifies a signature over the exact arguments inside. |
| `awaitTx` | `(hash: Hash, chain: EthereumChain) => Promise<TransactionReceipt>` | Waits for confirmation before advancing a flow. |

Every method that takes a chain gets it as an explicit parameter. Switch the wallet to that chain before acting - the SDK does not assume your wallet is already pointed at the right one. On a wallet session (a user signed in with their wallet instead of a CoinList login), a network change ends the session, because the session is bound to one address on one chain.

`signMessage` signs an EIP-191 personal message. The SDK passes the text exactly as CoinList wrote it, and a changed byte fails the signature. Send it to `personal_sign` hex-encoded, as viem's and wagmi's `signMessage({ message })` do. MetaMask recognizes a Sign-In With Ethereum challenge only in hex: sent as plain text, it shows a generic signature request and skips the check that warns the user when the page is not the site the message names.

`awaitTx` gets whatever hash your `writeContract` or `broadcastRawTx` returned. If your wallet returns anything other than a transaction hash, such as a Safe or userOp hash, resolving it to the transaction that mined is your job.

## Adapter: wagmi and AppKit

This is the canonical adapter, based on the one the [partner demo](https://github.com/coinlist/partner-demo) runs. Its `signMessage` goes through viem, which hex-encodes the message for `personal_sign`. `awaitTx` must resolve with the receipt even when the transaction reverted: the SDK reads `receipt.status` to report a mined revert as a step of its own. A wallet that throws there makes the revert look like an unconfirmed transaction. Any stack that can sign a message and send a transaction works the same way.

```ts wagmiEvmWallet.ts theme={null}
import type {
  EthereumChain,
  EvmWallet,
  EvmWalletAddress,
} from "@passage-cl/react/universal";
import {
  type Config,
  getChainId,
  getPublicClient,
  switchChain,
} from "@wagmi/core";
import { type Chain, encodeFunctionData, type WalletClient } from "viem";
import { base, baseSepolia, mainnet, sepolia } from "viem/chains";

// `Record<EthereumChain, Chain>` is total on purpose: the day the SDK models a
// new chain, this table fails to compile until you decide what it maps to.
const CHAINS: Record<EthereumChain, Chain> = {
  ethereum_mainnet: mainnet,
  ethereum_sepolia: sepolia,
  base_mainnet: base,
  base_sepolia: baseSepolia,
};

export function buildEvmWallet({
  address,
  walletClient,
  config,
}: {
  address: EvmWalletAddress;
  walletClient: WalletClient;
  config: Config;
}): EvmWallet {
  const account = address as `0x${string}`;

  // Each call passes the target chain; switch the wallet there first.
  const ensureChain = async (chain: EthereumChain): Promise<Chain> => {
    const target = CHAINS[chain];
    if (getChainId(config) !== target.id) {
      await switchChain(config, { chainId: target.id });
    }
    return target;
  };

  return {
    address,
    signMessage: (message) => walletClient.signMessage({ account, message }),
    async writeContract({ abi, address: to, functionName, args, value, chain }) {
      const targetChain = await ensureChain(chain);
      const data = encodeFunctionData({ abi, functionName, args });
      return walletClient.sendTransaction({
        account,
        chain: targetChain,
        to,
        data,
        value,
      });
    },
    async broadcastRawTx({ to, data, chain }) {
      const targetChain = await ensureChain(chain);
      return walletClient.sendTransaction({ account, chain: targetChain, to, data });
    },
    // viem's waitForTransactionReceipt, not @wagmi/core's: wagmi's throws on a
    // reverted receipt, and the SDK needs that receipt to report the revert.
    async awaitTx(hash, chain) {
      const client = getPublicClient(config, { chainId: CHAINS[chain].id });
      if (!client) throw new Error(`No wagmi client configured for ${chain}`);
      return client.waitForTransactionReceipt({ hash });
    },
  };
}
```

```bash theme={null}
npm install @passage-cl/react wagmi @wagmi/core viem @reown/appkit @reown/appkit-adapter-wagmi @tanstack/react-query
```

## Let wallet errors propagate

**Do not catch and translate your wallet library's errors.** Let them throw. The SDK catches them and classifies them into a typed `WalletError`, so you never parse a wallet error string yourself. It walks viem's error `cause` chain, so a rejection wrapped two levels deep still classifies:

| `WalletError` `type` | Cause |
| - | - |
| `user_rejected` | The user dismissed the wallet prompt. That covers viem's `UserRejectedRequestError` and any error with the EIP-1193 code `4001`, including a plain provider error object. |
| `insufficient_funds` | The account's native token cannot pay the gas plus the transaction's `value`. |
| `contract_reverted` | The wallet refused to send a transaction that would revert, usually when it estimated gas. This includes calldata a backend built, which the SDK sends through `broadcastRawTx`: Ondo swaps, Centrifuge requests and claims, and the Superstate allowlist transaction. Carries `reason`: the contract's revert string, error name, or selector, or `null` when the revert carried no data. |
| `timeout` | Confirmation did not arrive in time. Carries the transaction `hash`. |
| `disconnected` | The wallet is no longer connected, or no longer on the account `address` names, so nothing was sent. Retrying through the same wallet fails the same way: the user has to reconnect or choose another wallet. Added in v0.15.1, so an exhaustive `switch` on `WalletError` needs a case for it. |
| `unknown` | Anything the SDK could not classify. Carries the raw `cause`. |

Before v0.15.0, a backend-built transaction that reverted at gas estimation classified as `unknown`. It is now `contract_reverted`, with the contract's `reason`. Before v0.17.0, a plain `4001` from a signer that calls the provider directly classified as `unknown`. It now reads as `user_rejected`, so a user who cancels is not told something failed.

### Report a disconnected wallet

When an `EvmWallet` method cannot act because the wallet is gone, throw `WalletDisconnectedError`. That covers a wallet that disconnected and a user who switched to an account other than the wallet's `address`. The SDK classifies it as `disconnected`, and the checkouts and the Centrifuge claim ask the user to reconnect instead of to try again.

`WalletDisconnectedError` is exported from `@passage-cl/react/universal` only. Its constructor is `(message?, { cause? })`, so you can pass your wallet library's own error as the `cause`. The SDK recognizes it by its `name` as well as by `instanceof`, so one thrown from a second copy of the SDK still classifies.

```ts guardAccount.ts theme={null}
import {
  type EvmWallet,
  WalletDisconnectedError,
} from "@passage-cl/react/universal";

// Wraps an adapter so every call first checks that your wallet stack still
// exposes this wallet's address. With wagmi, pass
// `() => getAccount(config).address`.
export function guardAccount(
  wallet: EvmWallet,
  currentAddress: () => string | undefined,
): EvmWallet {
  const assertConnected = () => {
    if (currentAddress()?.toLowerCase() !== wallet.address.toLowerCase()) {
      throw new WalletDisconnectedError("The account changed.");
    }
  };

  return {
    address: wallet.address,
    signMessage: async (message) => {
      assertConnected();
      return wallet.signMessage(message);
    },
    writeContract: async (params) => {
      assertConnected();
      return wallet.writeContract(params);
    },
    broadcastRawTx: async (params) => {
      assertConnected();
      return wallet.broadcastRawTx(params);
    },
    awaitTx: (hash, chain) => wallet.awaitTx(hash, chain),
  };
}
```

You do not need it when your wallet library already says so. The SDK walks the whole `cause` chain, not only viem's, and treats these the same way:

* an error with the EIP-1193 code `4100` (viem's `UnauthorizedProviderError`), including a plain provider error object
* wagmi's `ConnectorNotConnectedError`
* a `WalletDisconnectedError` anywhere in the chain

A transaction that mines and then reverts is not a `WalletError`. The flow reports it as a step of its own, such as `approval-reverted` or `swap-reverted`. A receipt does not say why a transaction reverted, so when your `Config.logger` runs at the `debug` level, the SDK replays the reverted transaction as an `eth_call` and logs the contract's reason. The replay waits at most 10 seconds. Below `debug`, the SDK sends no extra RPC request.

Flows surface a `WalletError` as the `cause` on the step that failed, so you can tell a user rejection apart from an infrastructure problem. See [Errors and edge cases](https://docs.passage.coinlist.co/sdk/errors.md) for the full breakdown.

## Proving wallet ownership

With a CoinList login, two identities are involved in a purchase, and they are not the same thing:

* The **CoinList session** (from [OAuth](https://docs.passage.coinlist.co/sdk/oauth-authentication.md)) identifies *who* is investing.
* The **wallet** is *where* the assets are delivered.

An ownership proof is what links them, which is why an offer with an `external_wallet` or `whitelisted_wallet` requirement has the user sign a message before they can transact. Some offers go further: the issuer only settles to wallets they have allowlisted. Superstate assets work this way, and the same allowlists are what make permissioned DeFi pools and RWA lending markets reachable.

Ownership proof is provider-agnostic, so it lives on the platform namespace rather than being duplicated per provider:

```ts theme={null}
const challenge = await passage.wallets.createOwnershipChallenge({
  challengeType: "siwe",          // or "plain"
  walletAddress: wallet.address,
  chain: "ethereum_mainnet",
  domain: window.location.host,
  uri: window.location.origin,
  statement: "Sign to prove you own this wallet.",
});

const signature = await wallet.signMessage(challenge.message);

const binding = await passage.wallets.connectExternal({
  offerId,
  offerOptionId,
  walletAddress: wallet.address,
  chain: "ethereum_mainnet",
  signature,
});
```

Every `passage.wallets` method requires a CoinList user, so a wallet session does not qualify. All of them except `connect` throw `NotAuthenticatedError` otherwise; `connect` returns a `not_authenticated` error instead.

In the browser, `passage.wallets.connect` runs the same three steps in one call: it requests a challenge (SIWE by default, with `domain` and `uri` taken from the current page), has the wallet sign it, and submits the signature. Its `wallet` is a `ConnectWallet`, and it never throws. It resolves `{ type: "success", binding }`, `{ type: "cancelled" }` (only when your optional `isCancelled` callback returns `true` before the signing or binding step), or `{ type: "error", error: { code, retryable } }`, where `code` is `not_authenticated`, `user_rejected`, `wallet_not_whitelisted`, `max_wallets_reached`, or `unknown`:

```ts theme={null}
const result = await passage.wallets.connect({
  wallet: {
    address: wallet.address,
    signMessage: (message) => wallet.signMessage(message),
    chain: "ethereum_mainnet",
  },
  offerId,
  offerOptionId,
});

if (result.type === "error" && !result.error.retryable) {
  // A terminal failure: signing again with this wallet cannot succeed.
}
```

`passage.wallets` also reads and removes those bindings: `list({ offerId, offerOptionId })` returns the wallets bound to an option, and `remove({ offerId, addressId })` unbinds one.

> [!TIP]
>
> You rarely need to write the sequence above. [`RequirementsChecklistContainer`](https://docs.passage.coinlist.co/sdk/requirements) runs it for you when an offer has an `external_wallet` or `whitelisted_wallet` requirement, and the [Superstate Swap](https://docs.passage.coinlist.co/sdk/swap-flow.md) allowlist flow wraps it in one idempotent call.

## CheckoutWalletSelection: what checkout takes

`EvmWallet` is what the SDK *drives*. `CheckoutWalletSelection` is what you *hand* [`CheckoutContainer`](https://docs.passage.coinlist.co/sdk/checkout): the wallets the buyer may spend from, your connector for an external one, and optionally the wallet you have already settled on.

It is the shared `WalletSelection` (from `@passage-cl/react/universal`, the same shape every SDK screen reads its wallets from) plus one checkout-only field, `preselected`:

```ts theme={null}
import type { CheckoutWalletSelection } from "@passage-cl/react";

const wallets: CheckoutWalletSelection = {
  // "loading" until your wallet stack has listed every embedded wallet,
  // then "ready" (the default). See "Loading wallets" below.
  status: embeddedWalletsListed ? "ready" : "loading",
  // The user's embedded (custodial) wallets, in display order.
  // Empty with status "ready" is a normal state, not an error.
  embedded: embeddedWallets,
  // The connected external wallet, or null while none is connected.
  external: externalWallet,
  // Your external-wallet connector, or null to offer none. With null and no
  // connected `external` wallet, the external-wallet row is hidden (for an
  // app with embedded wallets only).
  externalAdapter: {
    // Opens your wallet connector. The SDK reads the outcome from `external`
    // on the next render, not from a return value, so a redirect-based
    // connector works. Reject to report a declined or failed connection.
    connect: () => openConnectModal(),
    // Resolves once the external wallet is gone.
    disconnect: () => disconnect(),
  },
  // A wallet you have already settled on, or null to let the user pick.
  preselected: null,
};
```

`externalAdapter` is one object rather than two optional lambdas, because a screen that can connect a wallet must also be able to let it go. You can still pass a connected `external` with a `null` adapter, to show a wallet the user cannot change from the checkout. If your `disconnect` rejects, the SDK logs it and keeps the current selection.

`WalletSelection` also has two helpers, from `@passage-cl/react/universal`:

| Helper | Returns |
| - | - |
| `WalletSelection.all(selection)` | Every wallet in display order, embedded first, then the external one. Each address appears once, compared case-insensitively. |
| `WalletSelection.find(selection, address)` | The wallet you supply at `address` now, compared case-insensitively, or `null` when you supply none there. |

`find` is how a checkout tracks the wallet the user confirmed: it remembers the address and looks it up again on every render. So you can hand over a fresh `EvmWallet` for the same address after an account or chain change, and retire the old one. When you stop supplying that address, the checkout returns to its wallet step. See [When the wallet disconnects](https://docs.passage.coinlist.co/sdk/checkout.md#when-the-wallet-disconnects).

### Loading wallets

A wallet stack restores its wallets asynchronously after page load. Set `status: "loading"` until **every embedded wallet is listed**, then `"ready"`. Omitting `status` means `"ready"`.

Privy's `ready` alone is not enough: it turns true before the embedded wallet is listed, and while Privy logs in from your own session it is ready with no `user` yet. Wait until the embedded wallets you expect are in the list.

Only the claim card reads `status` today, and only for its Centrifuge offers: `ClaimContainer` with at least one `centrifuge::vault` offer among its `offers`. It is the one screen that would read an empty selection as "the user has nothing". Before the card's first answer, `"loading"` shows its loading state, reads no Centrifuge position and offers no connect. The card answers for every offer or for none, so while it loads, its token-sale rows wait too. Once it shows content, a switch back to `"loading"` keeps that content until `"ready"`. A card of token sales only, and every checkout, ignore `status`. See [Centrifuge Vaults](https://docs.passage.coinlist.co/sdk/centrifuge-vaults.md#claiming).

### Skipping the wallet step

Set `preselected` to a ready `EvmWallet` when the page already knows the answer: a sell page reached from a position knows which wallet holds it, and an app with a single embedded wallet has only one answer on a buy too. Asking again would be a question with one possible answer. Every checkout honors it, in one of two ways:

* **Ondo buy, Ondo sell, Centrifuge buy, Centrifuge sell (redeem), and the CoinList token sale skip the wallet step.** The checkout opens on the amount and renumbers the cards that remain. The wallet does not have to appear in `embedded` or `external`: you supply a ready `EvmWallet`, and these flows never resolve it back to a row. On every render they look its address up in the current `preselected`, `embedded` and `external`, so a fresh `EvmWallet` at the same address is used. With no wallet step to return to, a preselected wallet that is gone fails its next send as `disconnected`.
* **Superstate never skips its wallet step**, because that step allowlists the wallet on-chain and no preselection can stand in for it. The step opens with the preselected wallet's row already selected, so the user confirms it rather than finding it. That needs a row: a preselected wallet that matches neither an `embedded` wallet nor the connected `external` one by address selects nothing.

It is read **once, at mount**. Changing it mid-flow is ignored: the approval that follows the amount step is granted by one specific wallet, and moving the flow onto another under it would strand that approval. If your preselection can change on one page, add `wallets.preselected?.address` to the checkout's remount `key`. After an order, the flow resets to the step it opened on, so a skipped wallet step stays skipped.

On a wallet session, the Ondo and Centrifuge checkouts pay from `wallets.external` and open on the amount, whatever you set in `preselected`. That wallet must be at the session's address. If it is not, even when the session's wallet is in `embedded`, the checkout shows a **Connect your wallet** card instead.

The rest of `wallets` stays live: a newly connected external wallet appears as a row without a remount, and a confirmed wallet you stop supplying sends the checkout back to its wallet step, when it has one.

There is deliberately no separate wallet model here: `EvmWallet` already carries the `address`, so an `{ address, signer }` pair would be a second wallet type to keep in sync with the first. Everything a wallet row displays beyond the address - the network name - comes from the checkout's execution chain rather than from the wallet, because that is the chain the transaction goes to whatever the wallet is currently pointed at.

## Next step

> [card] [Building the Checkout flow](https://docs.passage.coinlist.co/sdk/checkout.md)
>
> Hand your wallets to `CheckoutContainer` and let it render whichever provider the offer belongs to.


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