Quickstart
This guide will help you get started with@coinbase/cdp-core. You’ll learn how to install the package,
initialize the SDK, and make your first API call.
Installation
First, add the package to your project using your preferred package manager.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
Initialize the SDK
Before calling any methods in the SDK, you must first initialize it: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.
Account Configuration
You can configure the SDK to create different types of accounts for new users: Smart Account Configuration:ethereum.createOnLogin is set to "smart", the SDK will:
- Create an EOA (Externally Owned Account) first
- Use that EOA as the owner to create a Smart Account
- Both accounts will be available on the user object
solana.createOnLogin is set to true, the SDK will:
- Create a Solana account for new users
- The Solana account will be available on the
solanaAccountsproperty
Deferred Account Creation
You can omitcreateOnLogin entirely to prevent automatic account creation and instead create accounts manually when needed:
createOnLogin is omitted, the SDK will:
- Not create any accounts automatically upon user login
- Require manual account creation using the account creation actions (see below)
- Give you full control over when and what types of accounts to create
Sign In a User
You’re now ready to start calling the APIs provided by the package! The following code signs in an end user: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
Link a Phone Number
Link a Google Account
Link an Apple Account
Link Any OAuth Provider
Sign In with Custom Authentication
If you’re using a third-party identity provider (Auth0, Firebase, AWS Cognito, or any OIDC-compliant provider), you can authenticate users with JWTs from your provider.Prerequisites
Before using custom authentication:-
Configure your identity provider in the CDP Portal:
- Navigate to Embedded Wallet Configuration
- Click on the Custom auth tab
- Add your JWKS endpoint URL (e.g.,
https://your-domain.auth0.com/.well-known/jwks.json) - Configure your JWT issuer and audience
-
Provide a
customAuth.getJwtcallback when initializing the SDK:
Authenticate a User
Once configured, callauthenticateWithJWT() to authenticate the user:
How it Works
- Your user signs in to your identity provider (Auth0, Firebase, Cognito, etc.)
- You call
authenticateWithJWT()which internally calls yourcustomAuth.getJwtcallback - The SDK sends the JWT to CDP’s backend, which validates it against your configured JWKS
- If valid, the user is authenticated and wallets are auto-created based on your configuration
- The
customAuth.getJwtcallback is called automatically whenever the SDK needs a fresh token
View User Information
Once the end user has signed in, you can display their information in your application:Multi-Factor Authentication
The SDK supports Time-based One-Time Password (TOTP) multi-factor authentication to add an extra layer of security to your application. Users can enroll in MFA using authenticator apps like Google Authenticator or Authy.Important: Users must be authenticated (signed in) before they can enroll in MFA or perform MFA verification.
MFA Enrollment Flow
The enrollment flow consists of two steps:- Initiate enrollment - Generate a TOTP secret and QR code
- Submit enrollment - Verify the user’s authenticator app is configured correctly
MFA Verification Flow
When performing sensitive operations that require MFA verification, use the verification flow:Complete Example: MFA Setup and Usage
Create Accounts Manually
If you configured your SDK withoutcreateOnLogin, you can manually create accounts for authenticated users when needed. This gives you full control over when accounts are created.
Create an EVM EOA Account
createEvmEoaAccount() will throw an error if the user already has an EVM EOA account.
Create an EVM Smart Account
createEvmSmartAccount() will throw an error if the user already has an EVM Smart Account. If the user doesn’t have an EVM EOA, one will be automatically created first to serve as the EVM Smart Account owner.
You can also enable spend permissions when creating a Smart Account:
Create a Solana Account
createSolanaAccount() will throw an error if the user already has a Solana account.
Send an EVM Transaction
We support signing and sending an EVM transaction in a single call on the following networks:- Base
- Base Sepolia
- Ethereum
- Ethereum Sepolia
- Avalanche
- Arbitrum
- Optimism
- Polygon
viem to broadcast the transaction.
Smart Account Operations
Smart Accounts provide advanced account abstraction features, including user operations and paymaster support.Create Spend Permissions
Spend permissions allow Smart Accounts to delegate spending authority to other accounts within specified limits and time periods. This enables use cases like subscription payments, automated DeFi strategies, and automatic topping up of AI agent funds.periodInDays for a more human-friendly API:
List Spend Permissions
Retrieve all spend permissions for a Smart Account:Revoke Spend Permissions
Revoke a spend permission for a Smart Account:Sign a Solana Transaction
When your application is configured withsolana: { createOnLogin: true }, you can sign Solana transactions:
Sign a Solana Message
You can also sign arbitrary messages with Solana accounts:Send a Solana Transaction
You can sign and send a Solana transaction in a single call on the following Solana networks:- Solana Mainnet
- Solana Devnet
Send User Operations
Send user operations from a Smart Account:Get User Operation Status
After sending a user operation, you can get its status and retrieve the result: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:
X402 Payment Protocol Support
The SDK includes built-in support for the X402 payment protocol, which enables HTTP requests with micropayments. This allows accessing paid APIs and services that require payment for each request.Installation
Ensure you have separately installed thex402-fetch package:
Basic Usage
ThefetchWithX402 function provides a wrapped fetch API that automatically handles X402 payment requests:
Advanced Configuration
You can customize the X402 behavior with options:How It Works
- When you make a request to an X402-protected resource, the server responds with a
402 Payment Requiredstatus - The wrapped fetch function automatically:
- Extracts payment details from the server’s response
- Creates and signs a payment transaction using the user’s wallet
- Includes the payment proof in a retry request
- The server validates the payment and returns the requested resource
Smart Account Support
By default,fetchWithX402 will use the user’s Smart Account if available, falling back to their regular EVM account:
Solana Support
Solana is supported out of the box withfetchWithX402. If your end user has both an EVM and Solana account, the EVM account will be used by default. You can pass a Solana address to fetchWithX402 to use the Solana account instead.
EIP-1193 Provider
The core package includes an EIP-1193 compatible provider. This provider can be used to sign and send transactions. The provider is created by callingcreateCDPEmbeddedWallet, which exposes a .provider attribute. createCDPEmbeddedWallet must be called with the desired chains to support as well as the transports for these chains.
The provider will initially connect to the first chain in the chains array. The transports are typically HTTP RPC endpoints, which are used internally for broadcasting non-Base transactions. For more information on transports, see Wagmi’s createConfig setup.
Viem Accounts
The core package includes atoViemAccount utility function that enables wrapping an embedded wallet into a Viem account compatible interface. This allows the account to act as a drop-in replacement for any library or framework that accepts Viem accounts.