Skip to main content

CdpClient

The CdpClient class is the main entry point for interacting with the Coinbase Developer Platform API. It manages authentication, API clients, and provides access to EVM, Solana, policy, and end-user operations.

Constructor

CdpClient(
    api_key_id: str | None = None,
    api_key_secret: str | None = None,
    wallet_secret: str | None = None,
    debugging: bool = False,
    base_path: str = "https://api.cdp.coinbase.com/platform",
    max_network_retries: int = 3,
    source: str = SDK_DEFAULT_SOURCE,
    source_version: str = __version__,
)
Instantiate the CdpClient.
api_key_id
str | None
The API key ID. Defaults to the CDP_API_KEY_ID environment variable.
api_key_secret
str | None
The API key secret. Defaults to the CDP_API_KEY_SECRET environment variable.
wallet_secret
str | None
The wallet secret. Defaults to the CDP_WALLET_SECRET environment variable.
debugging
bool
default:"False"
Whether to enable debugging.
base_path
str
default:"https://api.cdp.coinbase.com/platform"
The base path for API requests.
max_network_retries
int
default:"3"
The maximum number of network retries.
source
str
The source identifier.
source_version
str
The source version.
raises
ValueError
If required API credentials are missing.

Properties

evm

@property
def evm(self) -> EvmClient:
Get the EvmClient instance for EVM operations.
return
EvmClient
The EVM client instance.

solana

@property
def solana(self) -> SolanaClient:
Get the SolanaClient instance for Solana operations.
return
SolanaClient
The Solana client instance.

policies

@property
def policies(self) -> PoliciesClient:
Get the PoliciesClient instance for policy management.
return
PoliciesClient
The policies client instance.

end_user

@property
def end_user(self) -> EndUserClient:
Get the EndUserClient instance for end user operations.
return
EndUserClient
The end user client instance.

Methods

close

async def close(self) -> None:
Close the CDP client and release resources.
return
None
Returns None on success.

Context Manager

The CdpClient can be used as an async context manager:
async with CdpClient(
    api_key_id="your-api-key-id",
    api_key_secret="your-api-key-secret",
) as cdp:
    # Use the client
    account = await cdp.evm.create_account()
    # Automatically closed when exiting the context

Example Usage

Basic Initialization

from cdp import CdpClient

# Using environment variables
cdp = CdpClient()

# Explicit credentials
cdp = CdpClient(
    api_key_id="your-api-key-id",
    api_key_secret="your-api-key-secret",
    wallet_secret="your-wallet-secret",
)

Create an EVM Account

from cdp import CdpClient

cdp = CdpClient(
    api_key_id="your-api-key-id",
    api_key_secret="your-api-key-secret",
)

# Create an EVM account
account = await cdp.evm.create_account(name="My Account")
print(f"Account address: {account.address}")

# Close the client when done
await cdp.close()

Using Context Manager

from cdp import CdpClient

async with CdpClient(
    api_key_id="your-api-key-id",
    api_key_secret="your-api-key-secret",
) as cdp:
    # Create a Solana account
    account = await cdp.solana.create_account(name="My Solana Account")
    print(f"Solana address: {account.address}")

Build docs developers (and LLMs) love