@crossmint/client-sdk-react-ui

中文文档
5.1.0发布于 2026/11/10Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 12.1万

React SDK for integrating Crossmint Wallets into your application. Provides providers, hooks, and built-in UI for wallet creation, signing, OTP verification, and passkey flows.

原始使用文档
文档目录19 节
  1. Prerequisites
  2. Installation
  3. Quick Start
  4. 1. Setup Providers
  5. 2. Use Wallets
  6. Providers
  7. createOnLogin Configuration
  8. Hooks
  9. useWallet()
  10. useWalletOtpSigner()
  11. useAuth()
  12. Components
  13. ExportPrivateKeyButton
  14. React Native
  15. Wallets SDK
  16. Documentation
  17. SDK Reference Docs Generation
  18. License
  19. Protected buyer fields (in development)

Crossmint React SDK

React SDK for integrating Crossmint Wallets into your application. Provides providers, hooks, and built-in UI for wallet creation, signing, OTP verification, and passkey flows.

Prerequisites

Get a client API key from the Crossmint developer console. Ensure your key has the Wallet API scopes enabled, including wallets.fund for stagingFund.

Installation

npm install @crossmint/client-sdk-react-ui
# or
pnpm add @crossmint/client-sdk-react-ui
# or
yarn add @crossmint/client-sdk-react-ui

Quick Start

1. Setup Providers

With Crossmint Auth (default in staging)

"use client";

import {
  CrossmintProvider,
  CrossmintAuthProvider,
  CrossmintWalletProvider,
} from "@crossmint/client-sdk-react-ui";

export default function App({ children }) {
  return (
    <CrossmintProvider apiKey={process.env.NEXT_PUBLIC_CROSSMINT_API_KEY}>
      <CrossmintAuthProvider>
        <CrossmintWalletProvider
          createOnLogin={{
            chain: "base-sepolia",
            recoveryMethods: [{ type: "email" }],
          }}
        >
          {children}
        </CrossmintWalletProvider>
      </CrossmintAuthProvider>
    </CrossmintProvider>
  );
}

Bring Your Own Authentication

Use this when your app already has an auth provider, and in production: connect your provider and configure JWT Authentication in the Crossmint Console (see Move to Production). Then skip CrossmintAuthProvider and pass your provider's JWT to the wallets SDK. See the Custom Auth Guide for full details.

"use client";

import {
  CrossmintProvider,
  CrossmintWalletProvider,
} from "@crossmint/client-sdk-react-ui";

export default function App({ children }) {
  return (
    <CrossmintProvider apiKey={process.env.NEXT_PUBLIC_CROSSMINT_API_KEY}>
      <CrossmintWalletProvider
        createOnLogin={{
          chain: "base-sepolia",
          recoveryMethods: [
            {
              type: "email",
              email: "[email protected]",
            },
          ],
        }}
      >
        {children}
      </CrossmintWalletProvider>
    </CrossmintProvider>
  );
}

2. Use Wallets

import { useWallet } from "@crossmint/client-sdk-react-ui";

function WalletActions() {
  const { wallet, status } = useWallet();

  if (status === "in-progress") return <p>Loading wallet...</p>;
  if (!wallet) return <p>No wallet</p>;

  // Staging only: mints USDXM, Crossmint's test stablecoin, into the wallet
  const handleFund = async () => {
    await wallet.stagingFund(10);
  };

  const handleSend = async () => {
    const tx = await wallet.send("0xRecipient", "usdxm", "10");
    console.log("Transaction:", tx.explorerLink);
  };

  return (
    <div>
      <p>Wallet: {wallet.address}</p>
      <button onClick={handleFund}>Get 10 USDXM</button>
      <button onClick={handleSend}>Send 10 USDXM</button>
    </div>
  );
}

Providers

ProviderPurpose
CrossmintProviderRoot provider. Required for all Crossmint features.
CrossmintAuthProviderAuthentication (email OTP, Google, Twitter/X). Optional if using your own auth.
CrossmintWalletProviderWallet creation, device signer management, and built-in OTP/passkey UI.

createOnLogin Configuration

When createOnLogin is set on CrossmintWalletProvider, a wallet is automatically created when the user logs in:

<CrossmintWalletProvider
  createOnLogin={{
    chain: "base-sepolia",       // required — the blockchain
    recoveryMethods: [{ type: "email" }], // required — recovery method config
    signers: [{ type: "device" }], // optional — defaults to device signer
  }}
>

recoveryMethods accepts a list of methods on every chain, each able to recover the wallet on its own:

<CrossmintWalletProvider
  createOnLogin={{
    chain: "solana",
    recoveryMethods: [{ type: "email" }, { type: "external-wallet", address: "9WzD..." }],
  }}
>

Hooks

useWallet()

Returns the wallet instance and management functions:

const {
  wallet,              // Wallet | undefined
  status,              // "not-loaded" | "in-progress" | "loaded" | "error"
  getWallet,           // (props: { chain, alias? }) => Promise<Wallet | undefined>
  createWallet,        // (props: ClientSideWalletCreateArgs) => Promise<Wallet | undefined>
  createDeviceSigner,  // () => Promise<DeviceSignerDescriptor> | undefined
  createPasskeySigner, // (name: string) => Promise<RegisterSignerPasskeyParams>
} = useWallet();

useWalletOtpSigner()

For custom OTP UI when using email/phone recovery methods:

const { needsAuth, sendOtp, verifyOtp, reject } = useWalletOtpSigner();

useAuth()

Authentication state and login methods:

const { login, logout, user, status } = useAuth();

Components

ExportPrivateKeyButton

Renders a button to export the wallet's private key via TEE. Only renders for email/phone signers.

import { ExportPrivateKeyButton } from "@crossmint/client-sdk-react-ui";

<ExportPrivateKeyButton appearance={{ borderRadius: "12px" }} />

React Native

For React Native apps, see @crossmint/client-sdk-react-native-ui.

Wallets SDK

The wallet object returned by useWallet() is a Wallet instance. For wallet method documentation (send, balances, sign, etc.), see the @crossmint/wallets-sdk README.

Documentation

SDK Reference Docs Generation

Source JSDoc -> TypeDoc -> api.json -+
                                    +-> generate-reference.mjs -> MDX pages (docs/<product>/)
                     examples.json -+

Run with pnpm generate:docs or node scripts/generate-reference.mjs --product wallets.

License

Apache-2.0

Protected buyer fields (in development)

Render each protected UC field independently; an HTML form and Crossmint auth provider are not required. The provider supplies the browser client key; jwt may come from external authentication.

const codeRef = useRef<CrossmintProtectedInputRef>(null);

<CrossmintProvider apiKey={clientApiKey}>
  <CrossmintProtectedInput ref={codeRef} field={codeField} jwt={buyerJwt} />
</CrossmintProvider>

const result = await codeRef.current.collect();
if (result.status === "collected") {
  // Combine with ordinary answers in the application's complete UC response.
  answers[codeField.key] = result.input;
} else {
  showError(result.message);
}

Collection returns collected, invalid, unavailable or superseded. The developer owns submission and error rendering. Authentication changes and frame reloads invalidate pending host results. Only reference/outcome metadata crosses back from the hosted iframe. Authentication crosses the verified window channel, rather than the iframe URL.

Supported protected inputs are single-line text (visible or masked), number and integer. All use a nested Basis Theory TextElement; tokenization never reads plaintext in Crossmint browser code. Codes and identifiers use text to preserve exact spelling. Unchanged references are cached until expiry; edits, clear, auth or descriptor changes invalidate collection. Disabled controls may still be collected while submission is locked.

This replaces the password-only merchantUrl/onCreated interface. The matching hosted iframe and per-field collection are implemented locally. SDK publication, Reactor deployment and composed provider/browser qualification remain release gates. Track AGENT-473.

版本与发布记录

@crossmint/client-sdk-react-ui 共发布 384 个版本,首次发布于 2022/01/01;过去 12 个月发布了 87 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
5.1.0latest2026/11/10今天
5.0.12026/11/074 天前
5.0.02026/11/064 天前
4.13.42026/11/065 天前
4.13.32026/11/056 天前
4.13.22026/11/056 天前

其他发布通道:beta → 4.0.0-beta.7。

关于 @crossmint/client-sdk-react-ui 的常见问题

@crossmint/client-sdk-react-ui 是什么?

React SDK for integrating Crossmint Wallets into your application. Provides providers, hooks, and built-in UI for wallet creation, signing, OTP verification, and passkey flows.

如何安装 @crossmint/client-sdk-react-ui?

在项目目录运行 npm install @crossmint/client-sdk-react-ui,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=17.0.2)、react-dom(>=17.0.2)、@solana/web3.js(^1.98.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@crossmint/client-sdk-react-ui 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@crossmint/client-sdk-react-ui 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@crossmint/client-sdk-react-ui 可以商用吗?

@crossmint/client-sdk-react-ui 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@crossmint/client-sdk-react-ui 的下载量有多少?

根据 npm 官方下载统计,@crossmint/client-sdk-react-ui 在 2026/10/11 – 2026/11/09 这 30 天内被下载 120,749 次,日均约 4,025 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@crossmint/client-sdk-react-ui 还在维护吗?

最新版本 5.1.0 发布于 2026/11/10(今天);至今共发布 384 个版本,其中过去 12 个月发布了 87 个;首次发布于 2022/01/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。