cdp package

Subpackages

Submodules

cdp.analytics module

cdp.api_clients module

class cdp.api_clients.ApiClients(cdp_client)

Bases: object

A container class for all API clients used in the CDP SDK.

This class provides lazy-loaded access to various API clients, ensuring that each client is only instantiated when it’s first accessed.

_cdp_client

The CDP API client used to initialize individual API clients.

Type:

CdpApiClient

_evm_accounts

The EVMAccountsApi client instance.

Type:

Optional[EVMAccountsApi]

_evm_smart_accounts

The EVMSmartAccountsApi client instance.

Type:

Optional[EVMSmartAccountsApi]

_evm_swaps

The EVMSwapsApi client instance.

Type:

Optional[EVMSwapsApi]

_evm_token_balances

The EVMTokenBalancesApi client instance.

Type:

Optional[EVMTokenBalancesApi]

_faucets

The FaucetsApi client instance.

Type:

Optional[FaucetsApi]

_solana_accounts

The SolanaAccountsApi client instance.

Type:

Optional[SolanaAccountsApi]

async close()

Close the CDP client asynchronously.

property evm_accounts: EVMAccountsApi

Get the EVMAccountsApi client instance.

Returns:

The EVMAccountsApi client instance.

Return type:

EVMAccountsApi

Note

This property lazily initializes the EVMAccountsApi client on first access.

property evm_smart_accounts: EVMSmartAccountsApi

Get the EVMSmartAccountsApi client instance.

Returns:

The EVMSmartAccountsApi client instance.

Return type:

EVMSmartAccountsApi

Note

This property lazily initializes the EVMSmartAccountsApi client on first access.

property evm_swaps: EVMSwapsApi

Get the EVMSwapsApi client instance.

Returns:

The EVMSwapsApi client instance.

Return type:

EVMSwapsApi

Note

This property lazily initializes the EVMSwapsApi client on first access.

property evm_token_balances: EVMTokenBalancesApi

Get the EVMTokenBalancesApi client instance.

Returns:

The EVMTokenBalancesApi client instance.

Return type:

EVMTokenBalancesApi

Note

This property lazily initializes the EVMTokenBalancesApi client on first access.

property faucets: FaucetsApi

Get the FaucetsApi client instance.

Returns:

The FaucetsApi client instance.

Return type:

FaucetsApi

Note

This property lazily initializes the FaucetsApi client on first access.

property payments: PaymentsAlphaApi

Get the PaymentsAlphaApi client instance.

Returns:

The PaymentsAlphaApi client instance.

Return type:

PaymentsAlphaApi

Note

This property lazily initializes the PaymentsAlphaApi client on first access.

property policies: PolicyEngineApi

Get the PolicyEngineApi client instance.

Returns:

The PolicyEngineApi client instance.

Return type:

PolicyEngineApi

Note

This property lazily initializes the PolicyEngineApi client on first access.

property solana_accounts: SolanaAccountsApi

Get the SolanaAccountsApi client instance.

Returns:

The SolanaAccountsApi client instance.

Return type:

SolanaAccountsApi

Note

This property lazily initializes the SolanaAccountsApi client on first access.

cdp.cdp_client module

cdp.constants module

Specifies package level constants used throughout the package.

cdp.constants.SDK_DEFAULT_SOURCE = 'sdk'

The public RSA key used to encrypt the private key when importing an EVM account.

cdp.evm_call_types module

class cdp.evm_call_types.EncodedCall(**data)

Bases: BaseModel

Represents an encoded call to a smart contract.

data: Optional[NewType(HexStr, str)]
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

to: NewType(HexAddress, NewType(HexStr, str))
value: Optional[NewType(Wei, int)]
class cdp.evm_call_types.FunctionCall(**data)

Bases: BaseModel

Represents a call to a smart contract that needs to be encoded using the ABI.

abi: list[dict[str, Any]]
args: list[Any]
function_name: str
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

to: NewType(HexAddress, NewType(HexStr, str))
value: Optional[NewType(Wei, int)]

cdp.evm_client module

cdp.evm_local_account module

cdp.evm_message_types module

cdp.evm_server_account module

class cdp.evm_server_account.EvmServerAccount(evm_server_account_model, evm_accounts_api, api_clients)

Bases: BaseAccount, BaseModel

A class representing an EVM server account.

property address: str

Get the EVM Account Address.

Returns:

The EVM account address.

Return type:

str

async fund(network, amount, token)

Fund an EVM account.

Parameters:
  • network (Literal['base']) – The network to fund the account on.

  • amount (int) – The amount of the token to fund in atomic units (e.g. 1000000 for 1 USDC).

  • token (Literal['eth', 'usdc']) – The token to fund.

Returns:

The result of the fund operation containing:
  • transfer: A Transfer object with details about the transfer including:
    • id: The transfer ID

    • status: The status of the transfer (e.g. “pending”, “completed”, “failed”)

    • source_amount: The amount in source currency

    • source_currency: The source currency

    • target_amount: The amount in target currency

    • target_currency: The target currency

    • fees: List of fees associated with the transfer

Return type:

FundOperationResult

async list_token_balances(network, page_size=None, page_token=None)

List the token balances for the account on the given network.

Parameters:
  • network (str) – The network to list the token balances for.

  • page_size (int, optional) – The number of token balances to return per page. Defaults to None.

  • page_token (str, optional) – The token for the next page of token balances, if any. Defaults to None.

Returns:

The token balances for the account on the network.

Return type:

[ListTokenBalancesResult]

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

property name: str | None

Get the name of the EVM account.

Returns:

The name of the EVM account.

Return type:

str | None

property policies: list[str]

Gets the list of policies the apply to this account.

Returns:

The list of Policy IDs.

Return type:

str

async quote_fund(network, amount, token)

Quote a fund operation.

Parameters:
  • network (Literal['base']) – The network to fund the account on.

  • amount (int) – The amount of the token to fund in atomic units (e.g. 1000000 for 1 USDC).

  • token (Literal['eth', 'usdc']) – The token to fund.

Returns:

A quote object containing:
  • quote_id: The ID of the quote

  • network: The network the quote is for

  • fiat_amount: The amount in fiat currency

  • fiat_currency: The fiat currency (e.g. “usd”)

  • token_amount: The amount of tokens to receive

  • token: The token to receive

  • fees: List of fees associated with the quote

Return type:

Quote

async quote_swap(from_token, to_token, from_amount, network, slippage_bps=None, signer_address=None, idempotency_key=None)

Get a quote for swapping tokens.

This is a convenience method that calls the underlying create_swap_quote with the account’s address as the taker.

Parameters:
  • from_token (str) – The contract address of the token to swap from

  • to_token (str) – The contract address of the token to swap to

  • from_amount (str | int) – The amount to swap from (in smallest unit)

  • network (str) – The network to execute the swap on

  • slippage_bps (Optional[int]) – Maximum slippage in basis points (100 = 1%). Defaults to 100.

  • signer_address (Optional[str]) – The address that will sign the transaction (for smart accounts). Currently unused.

  • idempotency_key (Optional[str]) – Optional idempotency key for safe retryable requests.

Returns:

The swap quote with transaction data

Return type:

QuoteSwapResult

Examples

>>> # Get a quote for swapping USDC to WETH (account as taker)
>>> quote = await account.quote_swap(
...     from_token="0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",  # USDC
...     to_token="0x4200000000000000000000000000000000000006",  # WETH
...     from_amount="100000000",  # 100 USDC
...     network="base",
...     idempotency_key="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
... )
>>> print(f"Expected output: {quote.to_amount}")
>>>
>>> # Execute the quote if satisfied
>>> result = await account.swap(AccountSwapOptions(swap_quote=quote))
async request_faucet(network, token)

Request a token from the faucet.

Parameters:
  • network (str) – The network to request the faucet for.

  • token (str) – The token to request the faucet for.

Returns:

The transaction hash of the faucet request.

Return type:

str

async send_transaction(transaction, network, idempotency_key=None)

Send an EVM transaction.

Parameters:
  • transaction (str | TransactionDictType | DynamicFeeTransaction) –

    The transaction to send.

    This can be either an RLP-encoded transaction to sign and send, as a 0x-prefixed hex string, or an EIP-1559 transaction request object.

    Use TransactionRequestEIP1559 if you would like Coinbase to manage the nonce and gas parameters.

    You can also use DynamicFeeTransaction from eth-account, but you will have to set the nonce and gas parameters manually.

    These are the fields that can be contained in the transaction object:

    • to: (Required) The address of the contract or account to send the transaction to.

    • value: (Optional) The amount of ETH, in wei, to send with the transaction.

    • data: (Optional) The data to send with the transaction; only used for contract calls.

    • gas: (Optional) The amount of gas to use for the transaction.

    • nonce: (Optional) The nonce to use for the transaction. If not provided, the API will assign a nonce to the transaction based on the current state of the account.

    • maxFeePerGas: (Optional) The maximum fee per gas to use for the transaction. If not provided, the API will estimate a value based on current network conditions.

    • maxPriorityFeePerGas: (Optional) The maximum priority fee per gas to use for the transaction. If not provided, the API will estimate a value based on current network conditions.

    • accessList: (Optional) The access list to use for the transaction.

    • chainId: (Ignored) The value of the chainId field in the transaction is ignored.

    • from: (Ignored) Ignored in favor of the account address that is sending the transaction.

    • type: (Ignored) The transaction type must always be 0x2 (EIP-1559).

  • network (str) – The network.

  • idempotency_key (str, optional) – The idempotency key. Defaults to None.

Returns:

The transaction hash.

Return type:

str

async sign_message(signable_message, idempotency_key=None)

Sign the EIP-191 message.

Parameters:
  • signable_message (SignableMessage) – The encoded message, ready for signing

  • idempotency_key (Optional[str]) – Optional idempotency key

Return type:

SignedMessage

Returns:

The signed message

Raises:

AttributeError – If the signature response is missing required fields

async sign_transaction(transaction_dict, idempotency_key=None)

Sign a transaction dict.

Parameters:
  • transaction_dict (Dict[str, Union[Sequence[Dict[str, Union[NewType(HexStr, str), Sequence[NewType(HexStr, str)]]]], bytes, NewType(HexStr, str), int]]) – transaction with all fields specified

  • idempotency_key (Optional[str]) – Optional idempotency key

Return type:

SignedTransaction

Returns:

The signed transaction

Raises:

ValueError – If the signature response is missing required fields

async sign_typed_data(domain, types, primary_type, message, idempotency_key=None)

Sign an EVM typed data.

Parameters:
  • domain (EIP712Domain) – The domain of the message.

  • types (Dict[str, Any]) – The types of the message.

  • primary_type (str) – The primary type of the message.

  • message (Dict[str, Any]) – The message to sign.

  • idempotency_key (str, optional) – The idempotency key. Defaults to None.

Returns:

The signature.

Return type:

str

async swap(swap_options)

Execute a token swap.

Parameters:

swap_options (AccountSwapOptions) – The swap options

Returns:

The result containing the transaction hash

Return type:

AccountSwapResult

classmethod to_evm_account(address, name=None)

Construct an existing EvmAccount by its address and the name.

Parameters:
  • address (str) – The address of the EvmAccount to retrieve.

  • name (str | None) – The name of the EvmAccount.

Returns:

The retrieved EvmAccount object.

Return type:

EvmAccount

Raises:

Exception – If there’s an error retrieving the EvmAccount.

async transfer(to, amount, token, network)

Transfer an amount of a token from an account to another account.

Parameters:
  • to (str | BaseAccount) – The account or 0x-prefixed address to transfer the token to.

  • amount (int) – The amount of the token to transfer, represented as an atomic unit (e.g. 10000 for 0.01 USDC).

  • units. (The cdp module exports a parse_units util to convert to atomic)

  • Otherwise

  • below. (you can pass atomic units directly. See examples)

  • token (str) – The token to transfer.

  • network (str) – The network to transfer the token on.

Returns:

The result of the transfer.

Examples

>>> transfer = await sender.transfer(
...     to="0x9F663335Cd6Ad02a37B633602E98866CF944124d",
...     amount=10000,  # equivalent to 0.01 USDC
...     token="usdc",
...     network="base-sepolia",
... )

Using parse_units to specify USDC amount >>> from cdp import parse_units >>> transfer = await sender.transfer( … to=”0x9F663335Cd6Ad02a37B633602E98866CF944124d”, … amount=parse_units(“0.01”, 6), # USDC uses 6 decimal places … token=”usdc”, … network=”base-sepolia”, … )

Transfer to another account >>> sender = await cdp.evm.create_account(name=”Sender”) >>> receiver = await cdp.evm.create_account(name=”Receiver”) >>> >>> transfer = await sender.transfer({ … “to”: receiver, … “amount”: 10000, # equivalent to 0.01 USDC … “token”: “usdc”, … “network”: “base-sepolia”, … })

async unsafe_sign_hash(message_hash, idempotency_key=None)

Sign the hash of a message.

WARNING: Never sign a hash that you didn’t generate, it can be an arbitrary transaction.

Parameters:
  • message_hash (NewType(Hash32, bytes)) – 32 byte hash of the message to sign

  • idempotency_key (Optional[str]) – Optional idempotency key

Return type:

SignedMessage

Returns:

The signed message

Raises:

ValueError – If the signature response is missing required fields

async wait_for_fund_operation_receipt(transfer_id, timeout_seconds=900, interval_seconds=1)

Wait for a fund operation to complete.

Parameters:
  • transfer_id (str) – The ID of the transfer to wait for.

  • timeout_seconds (float) – The maximum time to wait for completion in seconds. Defaults to 900 (15 minutes).

  • interval_seconds (float) – The time between status checks in seconds. Defaults to 1.

Returns:

The completed transfer object containing:
  • id: The transfer ID

  • status: The final status of the transfer (“completed” or “failed”)

  • source_amount: The amount in source currency

  • source_currency: The source currency

  • target_amount: The amount in target currency

  • target_currency: The target currency

  • fees: List of fees associated with the transfer

Return type:

Transfer

Raises:

TimeoutError – If the transfer does not complete within the timeout period.

class cdp.evm_server_account.ListEvmAccountsResponse(**data)

Bases: BaseModel

Response model for listing EVM accounts.

accounts: list[EvmServerAccount]
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

next_page_token: str | None

cdp.evm_smart_account module

class cdp.evm_smart_account.EvmSmartAccount(address, owner, name=None, api_clients=None)

Bases: BaseModel

A class representing an EVM smart account.

property address: str

Get the Smart Account Address.

Returns:

The Smart Account Address.

Return type:

str

async fund(network, amount, token)

Fund an EVM account.

Parameters:
  • network (Literal['base']) – The network to fund the account on.

  • amount (int) – The amount of the token to fund in atomic units (e.g. 1000000 for 1 USDC).

  • token (Literal['eth', 'usdc']) – The token to fund.

Returns:

The result of the fund operation containing:
  • transfer: A Transfer object with details about the transfer including:
    • id: The transfer ID

    • status: The status of the transfer (e.g. “pending”, “completed”, “failed”)

    • source_amount: The amount in source currency

    • source_currency: The source currency

    • target_amount: The amount in target currency

    • target_currency: The target currency

    • fees: List of fees associated with the transfer

Return type:

FundOperationResult

async get_user_operation(user_op_hash)

Get a user operation for the smart account by hash.

Parameters:

user_op_hash (str) – The hash of the user operation to get.

Returns:

The user operation model.

Return type:

EvmUserOperationModel

async list_token_balances(network, page_size=None, page_token=None)

List the token balances for the smart account on the given network.

Parameters:
  • network (str) – The network to list the token balances for.

  • page_size (int, optional) – The number of token balances to return per page. Defaults to None.

  • page_token (str, optional) – The token for the next page of token balances, if any. Defaults to None.

Returns:

The token balances for the smart account on the network.

Return type:

[ListTokenBalancesResult]

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

property name: str | None

Get the name of the smart account.

Returns:

The name of the smart account.

Return type:

str | None

property owners: list[BaseAccount]

Get the account owners.

Returns:

List of owner accounts

Return type:

List[BaseAccount]

async quote_fund(network, amount, token)

Quote a fund operation.

Parameters:
  • network (Literal['base']) – The network to fund the account on.

  • amount (int) – The amount of the token to fund in atomic units (e.g. 1000000 for 1 USDC).

  • token (Literal['eth', 'usdc']) – The token to fund.

Returns:

A quote object containing:
  • quote_id: The ID of the quote

  • network: The network the quote is for

  • fiat_amount: The amount in fiat currency

  • fiat_currency: The fiat currency (e.g. “usd”)

  • token_amount: The amount of tokens to receive

  • token: The token to receive

  • fees: List of fees associated with the quote

Return type:

Quote

async quote_swap(from_token, to_token, from_amount, network, slippage_bps=None, paymaster_url=None, idempotency_key=None)

Get a quote for swapping tokens with a smart account.

This is a convenience method that calls the underlying create_swap_quote with the smart account’s address as the taker and the owner’s address as the signer.

Parameters:
  • from_token (str) – The contract address of the token to swap from

  • to_token (str) – The contract address of the token to swap to

  • from_amount (str | int) – The amount to swap from (in smallest unit)

  • network (str) – The network to execute the swap on

  • slippage_bps (Optional[int]) – Maximum slippage in basis points (100 = 1%). Defaults to 100.

  • paymaster_url (Optional[str]) – Optional paymaster URL for gas sponsorship.

  • idempotency_key (Optional[str]) – Optional idempotency key for safe retryable requests.

Returns:

The swap quote with transaction data

Return type:

QuoteSwapResult

Raises:
  • ValueError – If parameters are invalid or liquidity is unavailable

  • Exception – If the API request fails

Examples

```python # Get a quote for swapping USDC to WETH (smart account as taker, owner as signer) quote = await smart_account.quote_swap(

from_token=”0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913”, # USDC to_token=”0x4200000000000000000000000000000000000006”, # WETH from_amount=”100000000”, # 100 USDC network=”base”, paymaster_url=”https://paymaster.example.com”, # Optional idempotency_key=”xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”

) print(f”Expected output: {quote.to_amount}”)

# Execute the quote if satisfied result = await smart_account.swap(network=”base”, swap_quote=quote) ```

async request_faucet(network, token)

Request a token from the faucet.

Parameters:
  • network (str) – The network to request the faucet for.

  • token (str) – The token to request the faucet for.

Returns:

The transaction hash of the faucet request.

Return type:

str

async send_user_operation(calls, network, paymaster_url=None)

Send a user operation for the smart account.

Parameters:
  • calls (List[ContractCall]) – The calls to send.

  • network (str) – The network.

  • paymaster_url (str) – The paymaster URL.

Returns:

The user operation model.

Return type:

EvmUserOperationModel

async swap(options)

Execute a token swap via user operation.

Parameters:

options (SmartAccountSwapOptions) – SmartAccountSwapOptions with either swap_quote OR inline parameters

Returns:

The user operation result containing:
  • user_op_hash: The user operation hash

  • smart_account_address: The smart account address

  • status: The operation status

Return type:

SmartAccountSwapResult

Raises:
  • ValueError – If liquidity is not available for the swap

  • Exception – If the swap operation fails

Examples

Using pre-created swap quote (recommended for inspecting details first): ```python from cdp.actions.evm.swap.types import SmartAccountSwapOptions

# First create a quote quote = await smart_account.quote_swap(

from_token=”0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913”, # USDC to_token=”0x4200000000000000000000000000000000000006”, # WETH from_amount=”100000000”, # 100 USDC network=”base”, idempotency_key=”…”

)

# Then execute the swap result = await smart_account.swap(

SmartAccountSwapOptions(

swap_quote=quote, idempotency_key=”…”

)

)

Using inline parameters (all-in-one pattern): ```python from cdp.actions.evm.swap.types import SmartAccountSwapOptions

result = await smart_account.swap(
SmartAccountSwapOptions(

network=”base”, from_token=”0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913”, # USDC to_token=”0x4200000000000000000000000000000000000006”, # WETH from_amount=”100000000”, # 100 USDC slippage_bps=100, # 1% slippage idempotency_key=”…”

)

)

classmethod to_evm_smart_account(address, owner, name=None)

Construct an existing smart account by its address and the owner.

Parameters:
  • address (str) – The address of the evm smart account to retrieve.

  • owner (BaseAccount) – The owner of the evm smart account.

  • name (str | None) – The name of the evm smart account.

Returns:

The retrieved EvmSmartAccount object.

Return type:

EvmSmartAccount

Raises:

Exception – If there’s an error retrieving the EvmSmartAccount.

async transfer(to, amount, token, network, paymaster_url=None)

Transfer an amount of a token from an account to another account.

Parameters:
  • to (str | BaseAccount) – The account or 0x-prefixed address to transfer the token to.

  • amount (int) – The amount of the token to transfer, represented as an atomic unit (e.g. 10000 for 0.01 USDC).

  • units. (The cdp module exports a parse_units util to convert to atomic)

  • Otherwise

  • below. (you can pass atomic units directly. See examples)

  • token (str) – The token to transfer.

  • network (str) – The network to transfer the token on.

  • paymaster_url (Optional[str]) – The paymaster URL to use for the transfer.

Returns:

The result of the transfer.

Examples

>>> transfer = await sender.transfer(
...     to="0x9F663335Cd6Ad02a37B633602E98866CF944124d",
...     amount=10000,  # equivalent to 0.01 USDC
...     token="usdc",
...     network="base-sepolia",
... )

Using parse_units to specify USDC amount >>> from cdp import parse_units >>> transfer = await sender.transfer( … to=”0x9F663335Cd6Ad02a37B633602E98866CF944124d”, … amount=parse_units(“0.01”, 6), # USDC uses 6 decimal places … token=”usdc”, … network=”base-sepolia”, … )

Transfer to another account >>> sender = await cdp.evm.create_smart_account( … owner=await cdp.evm.create_account(name=”Owner”), … ) >>> receiver = await cdp.evm.create_account(name=”Receiver”) >>> >>> transfer = await sender.transfer({ … “to”: receiver, … “amount”: 10000, # equivalent to 0.01 USDC … “token”: “usdc”, … “network”: “base-sepolia”, … })

async wait_for_fund_operation_receipt(transfer_id, timeout_seconds=900, interval_seconds=1)

Wait for a fund operation to complete.

Parameters:
  • transfer_id (str) – The ID of the transfer to wait for.

  • timeout_seconds (float) – The maximum time to wait for completion in seconds. Defaults to 900 (15 minutes).

  • interval_seconds (float) – The time between status checks in seconds. Defaults to 1.

Returns:

The completed transfer object containing:
  • id: The transfer ID

  • status: The final status of the transfer (“completed” or “failed”)

  • source_amount: The amount in source currency

  • source_currency: The source currency

  • target_amount: The amount in target currency

  • target_currency: The target currency

  • fees: List of fees associated with the transfer

Return type:

Transfer

Raises:

TimeoutError – If the transfer does not complete within the timeout period.

async wait_for_user_operation(user_op_hash, timeout_seconds=20, interval_seconds=0.2)

Wait for a user operation to be processed.

Parameters:
  • user_op_hash (str) – The hash of the user operation to wait for.

  • timeout_seconds (float, optional) – Maximum time to wait in seconds. Defaults to 20.

  • interval_seconds (float, optional) – Time between checks in seconds. Defaults to 0.2.

Returns:

The user operation model.

Return type:

EvmUserOperationModel

class cdp.evm_smart_account.ListEvmSmartAccountsResponse(**data)

Bases: BaseModel

Response model for listing EVM smart accounts.

accounts: list[EvmSmartAccount]
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

next_page_token: str | None

cdp.evm_token_balances module

class cdp.evm_token_balances.EvmToken(**data)

Bases: BaseModel

A token on an EVM network, which is either an ERC-20 or a native token (i.e. ETH).

contract_address: str
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str | None
network: ListEvmTokenBalancesNetwork
symbol: str | None
class cdp.evm_token_balances.EvmTokenAmount(**data)

Bases: BaseModel

A token amount on an EVM network.

amount: int
decimals: int
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class cdp.evm_token_balances.EvmTokenBalance(**data)

Bases: BaseModel

An EVM token balance.

amount: EvmTokenAmount
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

token: EvmToken
class cdp.evm_token_balances.ListTokenBalancesResult(**data)

Bases: BaseModel

The result of listing EVM token balances.

balances: list[EvmTokenBalance]
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

next_page_token: str | None

cdp.evm_transaction_types module

class cdp.evm_transaction_types.TransactionRequestEIP1559(**data)

Bases: BaseModel

Represents a transaction request using EIP-1559. Used with EthAccount’s DynamicFeeTransaction.

accessList: list[dict[str, Any]] | None
as_dict()

Serialize the TransactionRequestEIP1559 object to a dictionary.

Return type:

dict[str, Any]

chainId: int | None
data: Optional[NewType(HexStr, str)]
gas: int | None
maxFeePerGas: int | None
maxPriorityFeePerGas: int | None
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

nonce: int | None
to: NewType(HexAddress, NewType(HexStr, str))
type: str | None
value: int | None

cdp.export module

cdp.policies_client module

cdp.solana_account module

cdp.solana_client module

cdp.update_account_types module

cdp.utils module

exception cdp.utils.InvalidDecimalNumberError(value)

Bases: Exception

Exception raised for invalid decimal number strings.

Parameters:

value – The invalid decimal number string

cdp.utils.create_deterministic_uuid_v4(base_key, suffix='')

Create a deterministic UUID v4 from a base key and optional suffix.

This function generates a deterministic UUID by hashing the input components. Used for creating consistent idempotency keys across operations.

Parameters:
  • base_key (str) – The base key to generate the UUID from

  • suffix (str) – An optional suffix to append to the base key

Returns:

A deterministic UUID v4 string

Return type:

str

Examples

>>> create_deterministic_uuid_v4("my-base-key", "permit2")
"a1b2c3d4-e5f6-47a8-b9c0-d1e2f3a4b5c6"
>>> create_deterministic_uuid_v4("my-base-key")
"f1e2d3c4-b5a6-4798-8765-432109abcdef"
async cdp.utils.ensure_awaitable(func, *args, **kwargs)

Ensure a function call returns an awaitable result.

Works with both synchronous and asynchronous functions.

Parameters:
  • func – The function to call

  • *args – Arguments to pass to the function

  • **kwargs – Arguments to pass to the function

Returns:

The awaited result of the function

cdp.utils.parse_units(value, decimals)

Parse a decimal number string into an integer.

Parameters:
  • value (str) – The decimal number string to parse

  • decimals (int) – The number of decimal places

Return type:

int

Returns: The parsed integer

Raises:

InvalidDecimalNumberError – If the value is not a valid decimal number

cdp.utils.serialize_unsigned_transaction(transaction)

Serialize an unsigned transaction.

Parameters:

transaction (DynamicFeeTransaction) – The transaction to serialize

Return type:

str

Returns: The serialized transaction

cdp.utils.sort_keys(obj)

Recursively sorts object keys to ensure consistent JSON stringification.

Parameters:

obj (dict) – The object to sort

Return type:

dict

Returns:

A new object with sorted keys

Examples

>>> sort_keys({"b": 1, "a": 2})
{'a': 2, 'b': 1}
>>> sort_keys({"b": {"d": 1, "c": 2}, "a": 3})
{'a': 3, 'b': {'c': 2, 'd': 1}}

Module contents