Coinbase Developer Platform (CDP) provides React hooks for conveniently accessing the CDP Embedded Wallet SDK functionality on both EVM and Solana networks.Built on top of @coinbase/cdp-core, these hooks offer a React-friendly interface for authentication and embedded wallet operations.
For a complete list of available hooks with comprehensive method signatures, types, and examples, see the CDP Web SDK reference.
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:
If you’re not using the demo app from the Quickstart, you’ll need to manually set up the CDPHooksProvider in your application:
Using Next.js? Check out our Next.js integration guide for "use client" requirements and common gotchas.
Report incorrect code
Copy
Ask AI
import { CDPHooksProvider } from "@coinbase/cdp-hooks";function App() { return ( <CDPHooksProvider config={{ projectId: "your-project-id", basePath: "https://api.cdp.coinbase.com", // CDP API url useMock: false, // Use live APIs or use mock data for testing debugging: false, // Log API requests and responses }} > <YourApp /> </CDPHooksProvider> );}
Sign in with social providers using the OAuth flow. Note that the page from which the signInWithOAuth call occurs will be redirected back to after the user authenticates with their provider. The user will be automatically logged-in when @coinbase/cdp-core re-initializes.
Report incorrect code
Copy
Ask AI
import { useSignInWithOAuth } from "@coinbase/cdp-hooks";function SignIn() { const { signInWithOAuth } = useSignInWithOAuth(); const handleGoogleSignIn = () => { // User will be redirected to Google to complete their login // After login, they will be redirected back to your app, and the login // process will be completed automatically by the SDK void signInWithOAuth("google"); }; return <button onClick={handleGoogleSignIn}>Sign In with Google</button>;}
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 from viem to broadcast the transaction:
Report incorrect code
Copy
Ask AI
import { useSignEvmTransaction, useEvmAddress } from "@coinbase/cdp-hooks";import { http, createPublicClient } from "viem";import { tron } from "viem/chains";function NonBaseTransaction() { const { signEvmTransaction } = useSignEvmTransaction(); const { evmAddress } = useEvmAddress(); const handleSend = async () => { if (!evmAddress) return; try { // Sign the transaction const { signedTransaction } = await signEvmTransaction({ evmAccount: evmAddress, transaction: { to: evmAddress, // Send to yourself for testing value: 1000000000000n, // 0.000001 ETH in wei gas: 21000n, // Standard ETH transfer gas limit chainId: 728126428, // Tron type: "eip1559", // Modern gas fee model } }); // Broadcast using a different client const client = createPublicClient({ chain: tron, transport: http() }); const hash = await client.sendRawTransaction({ serializedTransaction: signedTransaction }); console.log("Transaction hash:", hash); } catch (error) { console.error("Transaction failed:", error); } }; return <button onClick={handleSend}>Send Transaction</button>;}
Private key export is a high-risk security operation. See our comprehensive Security & Export guide for proper implementation, security considerations, and best practices.
The 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 user operations from Smart Accounts with support for multiple calls and paymaster sponsorship. The hook returns a method to execute the user operation and forwards status, data, and error from its internal tracking.
Report incorrect code
Copy
Ask AI
import { useSendUserOperation, useCurrentUser } from "@coinbase/cdp-hooks";function SendUserOperation() { const { sendUserOperation } = useSendUserOperation(); const { currentUser } = useCurrentUser(); const handleSendUserOperation = async () => { const smartAccount = currentUser?.evmSmartAccounts?.[0]; if (!smartAccount) return; try { // This will automatically start tracking the user operation status const result = await sendUserOperation({ evmSmartAccount: smartAccount, network: "base-sepolia", calls: [{ to: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", value: 1000000000000000000n, data: "0x", }], }); console.log("User Operation Hash:", result.userOperationHash); } catch (error) { console.error("Failed to send user operation:", error); } }; return <button onClick={handleSendUserOperation}>Send User Operation</button>;}
The hook returns the 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.