Overview
CDP provides React hooks for conveniently accessing the CDP Embedded Wallet SDK functionality. Built on top of@coinbase/cdp-core
, these hooks offer a React-friendly interface for authentication and embedded wallet operations.
Check out the CDP Web SDK reference for comprehensive method signatures, types, and examples.
Available hooks
Available hooks
Auth and user management
useSignInWithEmail
- Initiate email authentication flowuseVerifyEmailOTP
- Verify OTP code sent to emailuseSignInWithSms
- Initiate SMS authentication flowuseVerifySmsOTP
- Verify OTP code sent via SMSuseCurrentUser
- Get the current authenticated useruseIsSignedIn
- Check if user is signed inuseSignOut
- Sign out the current useruseGetAccessToken
- Retrieve the access token of the current user
EVM wallet operations
useEvmAddress
- Get the primary EVM wallet addressuseSendEvmTransaction
- Send transactions on many EVM networks via CDPuseSignEvmTransaction
- Sign transactions for any EVM networkuseSignEvmMessage
- Sign plain text messagesuseSignEvmTypedData
- Sign EIP-712 typed datauseSignEvmHash
- Sign message hashesuseExportEvmAccount
- Export wallet private key
For a list of all EVM EOAs, call
useCurrentUser()
and read currentUser?.evmAccounts
.Smart account operations
useSendUserOperation
- Submit ERC-4337 user operations (batch calls) with optional Paymaster gas sponsorship
useEvmAddress()
returns the Smart Account if one exists; otherwise it returns the owner’s EOA.Solana wallet operations
useSolanaAddress
- Get the primary Solana wallet addressuseSendSolanaTransaction
- Send transactions on Solana mainnet or devnet via CDPuseSignSolanaTransaction
- Sign transactions on SolanauseSignSolanaMessage
- Sign base64-encoded messagesuseExportSolanaAccount
- Export wallet private key
For a list of all Solana accounts, call
useCurrentUser()
and read currentUser?.solanaAccounts
.SDK state
useIsInitialized
- Check if SDK is readyuseConfig
- Access CDP configuration
Prerequisites
The fastest way to get started is to complete the Quickstart. If you already have your own app, you should complete the prerequisites below before proceeding. You will need:- A CDP Portal account and CDP project
- Node.js 22+ installed
- Your local app domain configured in CDP Portal
- A package manager of your choice, with
cdp-hooks
installed:
1. Setup hooks provider
If you’re not using the demo app from the Quickstart, you’ll need to manually set up theCDPHooksProvider
in your application:
Using Next.js? Check out our Next.js integration guide for
"use client"
requirements and common gotchas.projectId
(required)ethereum.createOnLogin
="eoa" | "smart"
(optional)solana.createOnLogin
=boolean
(optional)basePath
(optional API base URL)useMock
(optional mock mode for local testing)debugging
(optional verbose API logging)
2. Ensure SDK initialization
Always ensure the SDK is initialized before authenticating a user or performing wallet operations:Hook examples
Now let’s explore how to use CDP hooks to build wallet functionality into your React application.User sign-in
Our authentication uses a two-step flow:- Submit user email to initiate the authentication flow, which will send the user a One-Time-Password (OTP) and return a
flowId
- Submit the six-digit OTP and
flowId
, after which the user will be authenticated, returning a User object
View user profile
Display user information and wallet addresses using CDP hooks:Send a transaction
We support signing and sending a blockchain transaction in a single action on the networks listed below. For other networks, see the next section.EVM networks:
- Base
- Base Sepolia
- Ethereum
- Ethereum Sepolia
- Arbitrum
- Avalanche
- Optimism
- Polygon
Solana networks:
- Solana Mainnet
- Solana Devnet
The
useSendEvmTransaction
hook also returns a data
state with statuses idle | pending | success | error
that reflects the most recent transaction.Sign and broadcast (non-supported EVM networks)
For networks other than those supported by the Send Transaction API, you can sign a transaction with the wallet and broadcast it yourself. This example uses the public client fromviem
to broadcast the transaction:
Sign messages and typed data
You can sign EVM (and Solana) messages, hashes, and typed data to generate signatures for various on-chain applications:Export private keys
Private key export is a high-risk security operation. See our comprehensive Security & Export guide for proper implementation, security considerations, and best practices.
useExportEvmAccount
and useExportSolanaAccount
hooks allows users to export their respective private keys for wallet migration or other purposes. For detailed implementation examples and security guidance, see the Security & Export documentation.
Send a user operation (Smart Accounts)
Send user operations from Smart Accounts with support for multiple calls and paymaster sponsorship. The hook returns a method to execute the user operation and forwardsstatus
, data
, and error
from its internal tracking.
sendUserOperation
method, which you call with the transaction parameters that you want to send. The hook also returns status
, data
, and error
values which you can use to track the status of the user operation. For more information, see the Smart Accounts guide.
What to read next
- CDP Web SDK Documentation: Comprehensive API reference for the CDP Web SDK
- Embedded Wallet - React Components: Pre-built UI components that work seamlessly with these hooks
- Embedded Wallet - Wagmi Integration: Use CDP wallets with the popular wagmi library
- Embedded Wallet - Next.js: Special considerations for Next.js applications
- Embedded Wallet - Smart Accounts: Dedicated guide for ERC-4337 features and paymasters (spend permissions coming soon)