@coinbase/cdp-react

中文文档
0.0.130发布于 2026/11/10TypeScriptES Module近 30 天下载 1.3万

This package contains ready-made, customizable React UI components that wrap the CDP frontend SDK.

原始使用文档
文档目录7 节
  1. Components
  2. Quickstart
  3. Installation
  4. Gather your CDP Project information
  5. Allowlist your local app
  6. Setup Provider
  7. Render a Component

This package contains ready-made, customizable React UI components that wrap the CDP frontend SDK.

Components

  • {@link SignInModal | SignInModal} - a button that triggers a modal with the sign-in flow
  • {@link SignIn | SignIn} - the forms for the sign in flow, a logo, heading, and description text
  • {@link SignOutButton | SignOutButton} - a sign out button
  • {@link AuthButton | AuthButton} - the SignOutButton when logged in, and the SignInModal when logged out
  • {@link SendEvmTransactionButton | SendEvmTransactionButton} - a button that signs and sends an EVM transaction
  • {@link SendSolanaTransactionButton | SendSolanaTransactionButton} - a button that signs and sends a Solana transaction
  • {@link Fund | Fund} - the fund flow
  • {@link FundModal | FundModal} - a button that triggers a modal with the fund flow
  • {@link LinkAuth | LinkAuth} - a component to link or unlink auth methods
  • {@link LinkAuthModal | LinkAuthModal} - a button that triggers a modal with the link / unlink flow
  • {@link CopyAddress | CopyAddress} - a component that renders a truncated address with a copy button
  • {@link CopyEvmKeyButton | CopyEvmKeyButton} - a button for copying the private key of a user's EVM EOA address
  • {@link CopySolanaKeyButton | CopySolanaKeyButton} - a button for copying the private key of a user's Solana address
  • {@link ExportWallet | ExportWallet} - wallet export controls with a security warning and copy buttons. Set exportFormat="mnemonic" for accounts whose availableExportFormats includes mnemonic. The export session resets automatically when the account or format changes.
  • {@link ExportWalletModal | ExportWalletModal} - a button that triggers a modal with the ExportWallet component
  • {@link EnrollMfa | EnrollMfa} - a component for MFA enrollment; guides users through setting up two-factor authentication via TOTP
  • {@link EnrollMfaModal | EnrollMfaModal} - a button that triggers a modal with the MFA enrollment flow
  • {@link VerifyMfa | VerifyMfa} - a component for MFA verification; prompts enrolled users to enter their authenticator code
  • {@link VerifyMfaModal | VerifyMfaModal} - a button that triggers a modal with the MFA verification flow
  • {@link VerifyMfaInline | VerifyMfaInline} - a wrapper component for embedding MFA verification within existing UI flows

Quickstart

This guide will help you get started with @coinbase/cdp-react. You'll learn how to install the package, set up the provider, and render your first component.

Installation

First, add the package to your project using your preferred package manager.

# With pnpm
pnpm add @coinbase/cdp-react @coinbase/cdp-core @coinbase/cdp-hooks

# With yarn
yarn add @coinbase/cdp-react @coinbase/cdp-core @coinbase/cdp-hooks

# With npm
npm install @coinbase/cdp-react @coinbase/cdp-core @coinbase/cdp-hooks

Gather your CDP Project information

  1. Sign in or create an account on the CDP Portal
  2. On your dashboard, select a project from the dropdown at the at the top, and copy the Project ID

Allowlist your local app

  1. Navigate to the Embedded Wallet Configuration in CDP Portal, and click Add origin to include your local app
  2. Enter the origin of your locally running app - e.g., http://localhost:3000
  3. Click Add origin again to save your changes

Setup Provider

Next, you need to wrap your application with the CDPReactProvider.

CDPReactProvider provides the necessary context for hooks and components to work correctly. It also provides access to config data and theming.

Update your main application file (e.g., main.tsx or App.tsx) to include the provider:

import React from 'react';
import ReactDOM from 'react-dom/client';
import { App } from './App'; // Your main App component
import { CDPReactProvider, type Config, type Theme } from '@coinbase/cdp-react';

// Config for your dapp
const config: Config = {
  projectId: "your-project-id", // Copy your Project ID here.
  appName: "My app", // the name of your application
  appLogoUrl: "https://picsum.photos/64", // logo will be displayed in select components
}

// You can customize the theme by overriding theme variables
const themeOverrides: Partial<Theme> = {
  "colors-bg-default": "black",
  "colors-bg-alternate": "#121212",
  "colors-fg-default": "white",
  "colors-fg-muted": "#999999",
}

ReactDOM.createRoot(document.getElementById('root')!).render(
  <React.StrictMode>
    <CDPReactProvider config={config} theme={themeOverrides}>
      <App />
    </CDPReactProvider>
  </React.StrictMode>,
);

Analytics Opt-Out

By default the SDK will emit usage analytics to help us improve the SDK. If you would like to opt-out, you can do so by setting the disableAnalytics configuration option to true.

<CDPReactProvider
  config={{
    projectId: "your-project-id",
    disableAnalytics: true,
  }}
>
  <App />
</CDPReactProvider>

Render a Component

Now you can use the components from the library. Let's add the AuthButton component to your application. This component handles both sign-in and sign-out functionality.

// In your App.tsx or any other component
import { AuthButton } from '@coinbase/cdp-react/components/AuthButton';

function App() {
  return (
    <div>
      <h1>Welcome</h1>
      <AuthButton />
    </div>
  );
}

export default App;

That's it! You've successfully installed @coinbase/cdp-react, set up the provider, and rendered your first component.

版本与发布记录

@coinbase/cdp-react 共发布 129 个版本,首次发布于 2025/07/12;过去 12 个月发布了 71 个版本。

版本发布日期距今
0.0.130latest2026/11/10今天
0.0.1292026/11/055 天前
0.0.1282026/10/2219 天前
0.0.1272026/10/071 个月前
0.0.1262026/09/191 个月前
0.0.1252026/09/191 个月前

其他发布通道:placeholder → 0.0.0。

关于 @coinbase/cdp-react 的常见问题

@coinbase/cdp-react 是什么?

This package contains ready-made, customizable React UI components that wrap the CDP frontend SDK.

如何安装 @coinbase/cdp-react?

在项目目录运行 npm install @coinbase/cdp-react,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18.2.0)、@coinbase/cdp-core(^0.0.130)、@coinbase/cdp-hooks(^0.0.130)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@coinbase/cdp-react 支持 TypeScript 吗?

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

@coinbase/cdp-react 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@coinbase/cdp-react 可以商用吗?

@coinbase/cdp-react 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@coinbase/cdp-react 的下载量有多少?

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

@coinbase/cdp-react 还在维护吗?

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