Skip to main content

Overview

The CDP Rust SDK provides a generated OpenAPI client for interacting with the Coinbase Developer Platform API. The client is fully async and supports both EVM and Solana blockchain operations.

Client Type

The main client type is generated from the OpenAPI specification:
use cdp_sdk::Client;

Constants

CDP_BASE_URL
&str
The default base URL for the CDP API: https://api.cdp.coinbase.com/platform

Creating a Client

Basic Client Creation

Create a client with authentication middleware:
use cdp_sdk::{auth::WalletAuth, Client, CDP_BASE_URL};
use reqwest_middleware::ClientBuilder;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize authentication from environment variables
    let wallet_auth = WalletAuth::builder().build()?;
    
    let http_client = ClientBuilder::new(reqwest::Client::new())
        .with(wallet_auth)
        .build();

    let client = Client::new_with_client(CDP_BASE_URL, http_client);

    Ok(())
}

Client with Explicit Credentials

Pass credentials directly instead of using environment variables:
use cdp_sdk::{auth::WalletAuth, Client, CDP_BASE_URL};
use reqwest_middleware::ClientBuilder;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let wallet_auth = WalletAuth::builder()
        .api_key_id("your-api-key-id".to_string())
        .api_key_secret("your-api-key-secret".to_string())
        .wallet_secret("your-wallet-secret".to_string())
        .build()?;

    let http_client = ClientBuilder::new(reqwest::Client::new())
        .with(wallet_auth)
        .build();

    let client = Client::new_with_client(CDP_BASE_URL, http_client);

    Ok(())
}

Client Methods

The client provides methods for all CDP API operations. All methods return request builders that can be configured with parameters before sending.

EVM Account Operations

create_evm_account
RequestBuilder
Creates a new EVM account
use cdp_sdk::types;

let body = types::CreateEvmAccountBody::builder()
    .name(Some("my-account".parse()?));

let response = client
    .create_evm_account()
    .x_wallet_auth("") // Automatically set by WalletAuth middleware
    .x_idempotency_key("unique-request-id")
    .body(body)
    .send()
    .await?;

let account = response.into_inner();
println!("Created account: {:?}", account);
get_evm_account
RequestBuilder
Retrieves an EVM account by address
let response = client
    .get_evm_account()
    .address("0x1234567890123456789012345678901234567890")
    .send()
    .await?;

let account = response.into_inner();
get_evm_account_by_name
RequestBuilder
Retrieves an EVM account by name
let response = client
    .get_evm_account_by_name()
    .name("my-account")
    .send()
    .await?;

let account = response.into_inner();
update_evm_account
RequestBuilder
Updates an existing EVM account
use cdp_sdk::types;

let update_body = types::UpdateEvmAccountBody::builder()
    .name(Some("updated-name".parse()?));

let response = client
    .update_evm_account()
    .address("0x1234567890123456789012345678901234567890")
    .body(update_body)
    .send()
    .await?;
list_evm_accounts
RequestBuilder
Lists all EVM accounts with pagination
let response = client
    .list_evm_accounts()
    .page_size(10)
    .send()
    .await?;

let accounts_list = response.into_inner();
for account in accounts_list.accounts {
    println!("Account: {} - {:?}", account.address, account.name);
}

Solana Account Operations

The client also provides similar methods for Solana accounts:
  • create_solana_account()
  • get_solana_account()
  • get_solana_account_by_name()
  • update_solana_account()
  • list_solana_accounts()

Error Handling

All client methods return a Result type that should be properly handled:
match client.get_evm_account().address("0x...").send().await {
    Ok(response) => {
        let account = response.into_inner();
        println!("Account found: {:?}", account);
    }
    Err(e) => {
        eprintln!("Error: {}", e);
    }
}

Types Module

The SDK includes a comprehensive types module with all API request and response types:
use cdp_sdk::types::{
    CreateEvmAccountBody,
    UpdateEvmAccountBody,
    EvmAccount,
    // ... and many more
};
All types are generated from the OpenAPI specification and include:
  • Request body types
  • Response types
  • Enum types for various options
  • Builder patterns for easy construction

See Also

Build docs developers (and LLMs) love