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:
Constants
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
Creates a new EVM accountuse 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);
Retrieves an EVM account by addresslet response = client
.get_evm_account()
.address("0x1234567890123456789012345678901234567890")
.send()
.await?;
let account = response.into_inner();
Retrieves an EVM account by namelet response = client
.get_evm_account_by_name()
.name("my-account")
.send()
.await?;
let account = response.into_inner();
Updates an existing EVM accountuse 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?;
Lists all EVM accounts with paginationlet 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