@coinbase/cdp-core, it offers a React-friendly interface for end user authentication
and embedded wallet operations.
Quickstart
This guide will help you get started with @coinbase/cdp-hooks. You’ll learn how to install the package, set up the provider, and use the hooks in both web and React Native applications.Installation
Web Applications
For web applications, add the package to your project using your preferred package manager:React Native Applications
For React Native applications, you’ll need additional crypto polyfills and dependencies:index.js or index.ts):
react-native-quick-crypto: Provides Web Crypto API compatibility for asymmetric key generation (ECDSA, RSA) required for JWT signing and encryptionreact-native-get-random-values: Provides secure random number generation viacrypto.getRandomValues()@ungap/structured-clone: PolyfillsstructuredClonefor object cloning compatibility@react-native-async-storage/async-storage: Provides persistent storage for auth tokens and secrets
Gather your CDP Project Information
- Sign in or create an account on the CDP Portal
- On your dashboard, select a project from the dropdown at the at the top, and copy the Project ID
Allowlist your local app
- Navigate to the Embedded Wallet Configuration in CDP Portal, and click Add origin to include your local app
- Enter the origin of your locally running app - e.g.,
http://localhost:3000 - Click Add origin again to save your changes
Setup Provider
Next, you need to wrap your application with the CDPHooksProvider, which provides the necessary context for hooks to work correctly.Web Applications
Update your main application file (e.g., main.tsx) to include the provider:React Native Applications
For React Native, the setup is identical.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 thedisableAnalytics configuration option to true.
Smart Account Configuration
You can configure the provider to automatically create Smart Accounts for new users:- When
ethereum.createOnLoginis set to"smart", new users will automatically get both an EOA and a Smart Account.
Solana Configuration
You can configure the provider to create Solana accounts for new users:- When
solana.createOnLoginis set totrue, new users will automatically get a Solana account instead of EVM accounts.
Sign In a User
End user authentication proceeds in two steps:- The user inputs their email address to initiate the authentication flow, which will send the user a One Time Password (OTP) and return a
flowId - The user submits the six-digit OTP and
flowId, after which the user will be authenticated, returning a User object.
Web Applications
React Native Applications
For React Native, you’ll use native UI components and handle the sign-in flow similarly:Link Additional Authentication Methods
Once a user is authenticated, you can link additional authentication methods to their account. This allows users to sign in using multiple methods (email, SMS, OAuth providers) with the same embedded wallet.Link an Email Address
Use theuseLinkEmail hook to link an email address to the currently authenticated user:
Link a Phone Number
Use theuseLinkSms hook to link a phone number to the currently authenticated user:
Link a Google Account
Use theuseLinkGoogle hook to link a Google account to the currently authenticated user:
Link an Apple Account
Use theuseLinkApple hook to link an Apple account to the currently authenticated user:
Link Any OAuth Provider
Use theuseLinkOAuth hook to link any supported OAuth provider (Google, Apple) to the currently authenticated user:
View User Information
Once the end user has signed in, you can display their information in your application:Working with Solana
When your application is configured withsolana: { createOnLogin: true }, you can use Solana-specific hooks to interact with Solana accounts.
Access Solana Address
Use theuseSolanaAddress hook to get the user’s primary Solana address:
Sign a Solana Transaction
Use theuseSignSolanaTransaction hook to sign Solana transactions:
Sign a Solana Message
Use theuseSignSolanaMessage hook to sign arbitrary messages with Solana accounts:
Send a Solana Transaction
Use theuseSendSolanaTransaction hook to sign and send Solana transactions in a single action. This is supported on:
- Solana Mainnet
- Solana Devnet
Send a Transaction
We support signing and sending a Blockchain transaction in a single action on the following networks:- Base
- Base Sepolia
- Ethereum
- Ethereum Sepolia
- Avalanche
- Arbitrum
- Optimism
- Polygon
viem to broadcast the transaction.
Sign Messages and Typed Data
End users can sign EVM messages, hashes, and typed data to generate signatures for various onchain applications.Export Private Keys
End users can export their private keys from their embedded wallet, allowing them to import them into compatible wallets of their choice.Export EVM Private Key
Export Solana Private Key
When your application is configured withsolana: { createOnLogin: true }, you can export Solana private keys:
Smart Account Operations
Smart Accounts provide advanced account abstraction features with React hooks.Create Spend Permissions
Spend permissions allow Smart Accounts to delegate spending authority to other accounts within specified limits and time periods. TheuseCreateSpendPermission hook provides an easy way to create spend permissions with automatic user operation tracking.
- Detects the user’s Smart Account (or allows you to specify
evmSmartAccount) - Converts
periodInDaysto seconds - Resolves token symbols like “eth” and “usdc” to contract addresses
- Tracks the user operation status and provides real-time updates
List Spend Permissions
Use theuseListSpendPermissions hook to retrieve all spend permissions for a Smart Account. This hook follows a query-style pattern and automatically fetches permissions when enabled.
Revoke Spend Permissions
Use theuseRevokeSpendPermission hook to revoke a spend permission. The hook automatically tracks the user operation and provides real-time status updates.
Send User Operations
Send user operations from Smart Accounts with support for multiple calls and paymaster sponsorship. The hook returns a method to execute the user operation andstatus, data, and error properties to read the result of the user operation:
Track User Operation Status
Use theuseWaitForUserOperation hook to poll for user operation status and provide real-time updates. This hook immediately fires off a query to get the result of the user operation:
Conditional Polling
You can control when theuseWaitForUserOperation hook should start polling using the enabled parameter: