Authentication
The CDP SDK uses a secure authentication system based on API keys, wallet secrets, and JWT (JSON Web Token) authentication. This guide explains how authentication works and how to configure it properly.Overview
CDP uses two types of credentials for authentication:- CDP API Keys - Used to authenticate all API requests
- Wallet Secret - Required for operations that create, modify, or delete accounts and send transactions
Authentication Flow
- SDK generates a JWT token using your API key
- JWT is signed with ES256 (EC) or EdDSA (Ed25519) algorithm
- Token is sent with each API request in the Authorization header
- For write operations, an additional Wallet Auth JWT is generated
Creating API Keys
Access the CDP Portal
Navigate to the CDP Portal and sign in to your account.
Create a new API Key
Click “Create API Key” and follow the prompts. You’ll receive:
- API Key ID - A UUID identifier for your key
- API Key Secret - The private key (either EC or Ed25519 format)
Create a Wallet Secret
In the same portal, create a Wallet Secret for signing transactions. This is a separate credential used for write operations.
Configuration Methods
There are multiple ways to configure authentication in CDP SDK:Method 1: Environment Variables (Recommended)
The simplest and most secure method for most applications:Method 2: Direct Configuration
Pass credentials directly to the client constructor:JWT Token Generation
The SDK automatically generates JWT tokens for authentication. Here’s how it works under the hood:API Key JWT
For standard API requests, the SDK generates a JWT with these claims:Wallet Auth JWT
For write operations (creating accounts, sending transactions), an additional Wallet Auth JWT is generated:The SDK handles all JWT generation automatically. You don’t need to manage tokens manually.
Key Formats
CDP supports two types of private key formats:EC Keys (ES256)
Elliptic Curve keys in PEM format:Ed25519 Keys (EdDSA)
Edwards curve keys in base64 format:Authentication Code Examples
Here’s how JWT authentication is implemented in the SDK:Read vs Write Operations
Read Operations
Read-only operations (like listing accounts or checking balances) only require the API Key JWT:Write Operations
Write operations require both API Key and Wallet Secret:If you try to perform a write operation without a wallet secret, you’ll receive an authentication error.
Security Best Practices
Never Expose Keys
Never commit API keys or secrets to version control or expose them in client-side code
Use Environment Variables
Store credentials in environment variables or secure secret management services
Rotate Keys Regularly
Regularly rotate your API keys and wallet secrets
Limit Key Permissions
Use separate keys for different environments (dev, staging, production)
Production Secret Management
For production environments, use dedicated secret management:- AWS Secrets Manager - For AWS-based deployments
- Google Cloud Secret Manager - For GCP deployments
- Azure Key Vault - For Azure deployments
- HashiCorp Vault - For multi-cloud or on-premises
- Doppler - For centralized secret management
Troubleshooting
Missing API Keys Error
If you see this error:- Set the environment variables
CDP_API_KEY_IDandCDP_API_KEY_SECRET - Or passed them directly to the
CdpClientconstructor
Invalid Key Format Error
If you see:Wallet Secret Required Error
If you see:CDP_WALLET_SECRET. Set it in your environment or pass it to the constructor.
Next Steps
Quickstart
Start building with authenticated API calls
API Reference
Explore all available API endpoints