- Secret API Keys: For server-to-server communication (i.e., REST APIs).
- Client API Keys: For client-side communication (i.e., JSON-RPC).
Prerequisites
It is assumed you are logged into an existing CDP account (if not, create one).1. Create an API key
Your CDP account should include a project by default. Navigate to your API keys dashboard. From the top drop-down, select your desired project.
Continue reading based on the type of API key you need to create.
Server
To create a Secret API key (for server-to-server communication), ensure the Secret API Keys tab is selected as shown in the previous step. Click the Create API key button and give your key a name. You also have the option to:- Set an IP allowlist for the key
- Restrict granular permissions such as the ability to trade or transfer funds
- Select between Ed25519 (Recommended) or ECDSA signature algorithms
Client
To create a Client API key (for use in front-end components) ensure the Client API Key tab is selected.
Copy the Client API key and export it as an environment variable:
2. Generate JWT (Server only)
You can generate a JSON Web Token (JWT) using the following code snippets.More on JWTs
More on JWTs
A JWT is a compact, self-contained, stateless token format used to securely transmit API keys as a JSON object for authentication with the CDP API.Read more in our JWT documentation.
- Set up your environment for JWT generation by configuring environment variables and installing dependencies
- Export your generated JWT as an environment variable
Setup
To begin, export the following environment variables:KEY_NAME: The name of the API key you want to useKEY_SECRET: The secret of the API key you want to useREQUEST_METHOD: The HTTP method of the endpoint you want to targetREQUEST_PATH: The path of the endpoint you want to targetREQUEST_HOST: The host of the endpoint you want to target
- Python
- JavaScript
- TypeScript
- Go
- Ruby
- PHP
- Java
- C++
- C#
Install required dependencies:
Export
Now that your environment is setup, you can create the code to generate the JWT and export it as an environment variable.Your JWT is valid for 2 minutes. After 2 minutes, you will need to generate a new JWT to ensure uninterrupted access to the CDP APIs.
- Python
- JavaScript
- TypeScript
- Go
- Ruby
- PHP
- Java
- C++
- C#
Create a new file for JWT generation code:It should contain the following:Finally, run the script to generate the JWT output and export it as an environment variable.
main.py
3. Authenticate
Server
To authenticate your server-side code, use the JWT token you generated in the previous step as a Bearer Token within your request:Client
To authenticate your client-side code, include it with your JSON-RPC request:What to read next
- Security Best Practices: Learn how to secure your API keys and other sensitive information.
- CDP API Keys: Learn how to create and manage your API keys.
- JWT Authentication: More information on JWT authentication.
- CDP cURL: Learn how to use our CLI tool to interact with the CDP API.
- Postman Files: Download our Postman collection and environment files to get started.