cdp package

Subpackages

Submodules

cdp.address module

class cdp.address.Address(network_id, address_id)

Bases: object

A class representing an address.

property address_id: str

Get the address ID.

Returns:

The address ID.

Return type:

str

balance(asset_id)

Get the balance of the address.

Parameters:

asset_id (str) – The asset ID.

Returns:

The balance of the address.

Return type:

Decimal

balances()

List balances of the address.

Returns:

The balances of the address, keyed by asset ID. Ether balances are denominated in ETH.

Return type:

BalanceMap

property can_sign: bool

Get whether the address can sign.

Returns:

Whether the address can sign.

Return type:

bool

faucet(asset_id=None)

Request faucet funds.

Parameters:

asset_id (str) – The asset ID.

Returns:

The faucet transaction object.

Return type:

FaucetTransaction

historical_balances(asset_id)

List historical balances.

Parameters:

asset_id (str) – The asset ID.

Returns:

An iterator of HistoricalBalance objects.

Return type:

Iterator[HistoricalBalance]

Raises:

Exception – If there’s an error listing the historical balances.

property network_id: str

Get the network ID.

Returns:

The network ID.

Return type:

str

transactions()

List transactions of the address.

Returns:

An iterator of Transaction objects.

Return type:

Iterator[Transaction]

Raises:

Exception – If there’s an error listing the transactions.

cdp.api_clients module

class cdp.api_clients.ApiClients(cdp_client)

Bases: object

A container class for all API clients used in the Coinbase 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

_wallets

The WalletsApi client instance.

Type:

Optional[WalletsApi]

_webhooks

The WebhooksApi client instance.

Type:

Optional[WebhooksApi]

_addresses

The AddressesApi client instance.

Type:

Optional[AddressesApi]

_external_addresses

The ExternalAddressesApi client instance.

Type:

Optional[ExternalAddressesApi]

_transfers

The TransfersApi client instance.

Type:

Optional[TransfersApi]

_networks

The NetworksApi client instance.

Type:

Optional[NetworksApi]

_assets

The AssetsApi client instance.

Type:

Optional[AssetsApi]

_trades

The TradesApi client instance.

Type:

Optional[TradesApi]

_contract_invocations

The ContractInvocationsApi client instance.

Type:

Optional[ContractInvocationsApi]

property addresses: AddressesApi

Get the AddressesApi client instance.

Returns:

The AddressesApi client instance.

Return type:

AddressesApi

Note

This property lazily initializes the AddressesApi client on first access.

property assets: AssetsApi

Get the AssetsApi client instance.

Returns:

The AssetsApi client instance.

Return type:

AssetsApi

Note

This property lazily initializes the AssetsApi client on first access.

property balance_history: BalanceHistoryApi

Get the BalanceHistoryApi client instance.

Returns:

The BalanceHistoryApi client instance.

Return type:

BalanceHistoryApi

Note

This property lazily initializes the BalanceHistoryApi client on first access.

property contract_invocations: ContractInvocationsApi

Get the ContractInvocationsApi client instance.

Returns:

The ContractInvocationsApi client instance.

Return type:

ContractInvocationsApi

Note

This property lazily initializes the ContractInvocationsApi client on first access.

property external_addresses: ExternalAddressesApi

Get the ExternalAddressesApi client instance.

Returns:

The ExternalAddressesApi client instance.

Return type:

ExternalAddressesApi

Note

This property lazily initializes the ExternalAddressesApi client on first access.

property fund: FundApi

Get the FundApi client instance.

Returns:

The FundApi client instance.

Return type:

FundApi

Note

This property lazily initializes the FundApi client on first access.

property networks: NetworksApi

Get the NetworksApi client instance.

Returns:

The NetworksApi client instance.

Return type:

NetworksApi

Note

This property lazily initializes the NetworksApi client on first access.

property smart_contracts: SmartContractsApi

Get the SmartContractsApi client instance.

Returns:

The SmartContractsApi client instance.

Return type:

SmartContractsApi

Note

This property lazily initializes the SmartContractsApi client on first access.

property trades: TradesApi

Get the TradesApi client instance.

Returns:

The TradesApi client instance.

Return type:

TradesApi

Note

This property lazily initializes the TradesApi client on first access.

property transaction_history: TransactionHistoryApi

Get the TransactionHistoryApi client instance.

Returns:

The TransactionHistoryApi client instance.

Return type:

TransactionHistoryApi

Note

This property lazily initializes the TransactionHistoryApi client on first access.

property transfers: TransfersApi

Get the TransfersApi client instance.

Returns:

The TransfersApi client instance.

Return type:

TransfersApi

Note

This property lazily initializes the TransfersApi client on first access.

property wallets: WalletsApi

Get the WalletsApi client instance.

Returns:

The WalletsApi client instance.

Return type:

WalletsApi

Note

This property lazily initializes the WalletsApi client on first access.

property webhooks: WebhooksApi

Get the WebhooksApi client instance.

Returns:

The WebhooksApi client instance.

Return type:

WebhooksApi

Note

This property lazily initializes the WebhooksApi client on first access.

cdp.asset module

class cdp.asset.Asset(network_id, asset_id, contract_address, decimals)

Bases: object

A class representing an asset.

property asset_id: str

Get the asset ID.

Returns:

The asset ID.

Return type:

str

property contract_address: str

Get the contract address.

Returns:

The contract address.

Return type:

str

property decimals: int

Get the number of decimals for the asset.

Returns:

The number of decimals.

Return type:

int

classmethod fetch(network_id, asset_id)

Fetch an asset from the API.

Parameters:
  • network_id (str) – The network ID.

  • asset_id (str) – The asset ID.

Returns:

The fetched Asset instance.

Return type:

Asset

from_atomic_amount(atomic_amount)

Convert an atomic amount to a whole amount.

Parameters:

atomic_amount (Decimal) – The atomic amount.

Returns:

The whole amount.

Return type:

Decimal

classmethod from_model(model, asset_id=None)

Create an Asset instance from a model.

Parameters:
  • model (AssetModel) – The model representing the asset.

  • asset_id (Optional[str]) – The asset ID.

Returns:

The Asset instance.

Return type:

Asset

property network_id: str

Get the network ID.

Returns:

The network ID.

Return type:

str

static primary_denomination(asset_id)

Get the primary denomination for a given asset ID.

Parameters:

asset_id (str) – The asset ID.

Returns:

The primary denomination of the asset.

Return type:

str

to_atomic_amount(whole_amount)

Convert a whole amount to an atomic amount.

Parameters:

whole_amount (Decimal) – The whole amount.

Returns:

The atomic amount.

Return type:

Decimal

cdp.balance module

class cdp.balance.Balance(amount, asset, asset_id=None)

Bases: object

A class representing a balance.

property amount: Decimal

Get the amount.

Returns:

The amount.

Return type:

Decimal

property asset: Asset

Get the asset.

Returns:

The asset.

Return type:

Asset

property asset_id: str

Get the asset ID.

Returns:

The asset ID.

Return type:

str

static from_model(model, asset_id=None)

Create a Balance instance from a model.

Parameters:
  • model (BalanceModel) – The model representing the balance.

  • asset_id (Optional[str]) – The asset ID.

Returns:

The Balance instance.

Return type:

Balance

cdp.balance_map module

class cdp.balance_map.BalanceMap

Bases: dict[str, Decimal]

A class representing asset balances.

This class extends the built-in dict class, where keys are asset IDs (str) and values are balance amounts (Decimal).

add(balance)

Add a Balance object to the BalanceMap.

Parameters:

balance (Balance) – The Balance object to add.

Raises:

ValueError – If the provided balance is not a Balance instance.

Return type:

None

classmethod from_models(models)

Create a BalanceMap instance from a list of BalanceModel objects.

Parameters:

models (List[BalanceModel]) – A list of BalanceModel objects.

Returns:

A new BalanceMap instance populated with the given models.

Return type:

BalanceMap

cdp.cdp module

class cdp.cdp.Cdp

Bases: object

The Cdp class is a singleton responsible for configuring and managing the Coinbase API client.

api_key_name

The API key name.

Type:

Optional[str]

private_key

The private key associated with the API key.

Type:

Optional[str]

use_server_signer

Whether to use the server signer.

Type:

bool

debugging

Whether debugging is enabled.

Type:

bool

base_path

The base URL for the Platform API.

Type:

str

max_network_retries

The maximum number of network retries.

Type:

int

api_clients

The Platform API clients instance.

Type:

Optional[ApiClients]

api_clients: ApiClients | None = None
api_key_name = None
base_path = 'https://api.cdp.coinbase.com/platform'
classmethod configure(api_key_name, private_key, use_server_signer=False, debugging=False, base_path='https://api.cdp.coinbase.com/platform', max_network_retries=3, source='sdk', source_version='0.12.1')

Configure the CDP SDK.

Parameters:
  • api_key_name (str) – The API key name.

  • private_key (str) – The private key associated with the API key.

  • use_server_signer (bool) – Whether to use the server signer. Defaults to False.

  • debugging (bool) – Whether debugging is enabled. Defaults to False.

  • base_path (str) – The base URL for the CDP API. Defaults to “https://api.cdp.coinbase.com/platform”.

  • max_network_retries (int) – The maximum number of network retries. Defaults to 3.

  • source (Optional[str]) – Specifies whether the sdk is being used directly or if it’s an Agentkit extension.

  • source_version (Optional[str]) – The version of the source package.

Return type:

None

classmethod configure_from_json(file_path='~/Downloads/cdp_api_key.json', use_server_signer=False, debugging=False, base_path='https://api.cdp.coinbase.com/platform', max_network_retries=3, source='sdk', source_version='0.12.1')

Configure the CDP SDK from a JSON file.

Parameters:
  • file_path (str) – The path to the JSON file. Defaults to “~/Downloads/cdp_api_key.json”.

  • use_server_signer (bool) – Whether to use the server signer. Defaults to False.

  • debugging (bool) – Whether debugging is enabled. Defaults to False.

  • base_path (str) – The base URL for the CDP API. Defaults to “https://api.cdp.coinbase.com/platform”.

  • max_network_retries (int) – The maximum number of network retries. Defaults to 3.

  • source (Optional[str]) – Specifies whether the sdk is being used directly or if it’s an Agentkit extension.

  • source_version (Optional[str]) – The version of the source package.

Raises:

InvalidConfigurationError – If the JSON file is missing the ‘api_key_name’ or ‘private_key’.

Return type:

None

debugging = False
max_network_retries = 3
private_key = None
use_server_signer = False

cdp.cdp_api_client module

class cdp.cdp_api_client.CdpApiClient(api_key, private_key, host='https://api.cdp.coinbase.com/platform', debugging=False, max_network_retries=3, source='sdk', source_version='0.12.1')

Bases: ApiClient

CDP API Client that handles authentication and API calls for Coinbase.

property api_key: str

The API key for authentication.

Returns:

The API key.

Return type:

str

call_api(method, url, header_params=None, body=None, post_params=None, _request_timeout=None)

Make the HTTP request (synchronous).

Parameters:
  • method – Method to call.

  • url – Path to method endpoint.

  • header_params – Header parameters to be

  • header. (placed in the request)

  • body – Request body.

  • post_params (dict) – Request post form parameters, for application/x-www-form-urlencoded, multipart/form-data.

  • _request_timeout – timeout setting for this request.

Return type:

RESTResponse

Returns:

RESTResponse

property debugging: str

Whether debugging is enabled.

Returns:

Whether debugging is enabled.

Return type:

bool

property private_key: str

The private key for authentication.

Returns:

The private key.

Return type:

str

response_deserialize(response_data, response_types_map=None)

Deserialize the API response.

Parameters:
  • response_data (RESTResponse) – REST response data.

  • response_types_map (Optional[dict[str, TypeVar(T)]]) – Map of response types.

Return type:

ApiResponse

Returns:

ApiResponse[ApiResponseT]

cdp.constants module

Specifies package level constants used throughout the package.

cdp.contract_invocation module

class cdp.contract_invocation.ContractInvocation(model)

Bases: object

A class representing a contract invocation.

property abi: dict[str, Any]

Get the ABI of the contract invocation.

Returns:

The ABI JSON.

Return type:

Dict

property address_id: str

Get the address ID of the contract invocation.

Returns:

The address ID.

Return type:

str

property amount: Decimal

Get the amount sent to the contract in atomic units.

Returns:

The amount in atomic units.

Return type:

Decimal

property args: dict[str, Any]

Get the arguments passed to the contract method.

Returns:

The arguments passed to the contract method.

Return type:

Dict

broadcast()

Broadcast the contract invocation to the network.

Returns:

The broadcasted ContractInvocation object.

Return type:

ContractInvocation

Raises:

TransactionNotSignedError – If the transaction is not signed.

property contract_address: str

Get the contract address.

Returns:

The contract address.

Return type:

str

property contract_invocation_id: str

Get the contract invocation ID.

Returns:

The contract invocation ID.

Return type:

str

classmethod create(address_id, wallet_id, network_id, contract_address, method, abi=None, args=None, amount=None, asset_id=None)

Create a new ContractInvocation object.

Parameters:
  • address_id (str) – The address ID of the signing address.

  • wallet_id (str) – The wallet ID associated with the signing address.

  • network_id (str) – The Network ID.

  • contract_address (str) – The contract address.

  • method (str) – The contract method.

  • abi (Optional[list[dict]]) – The contract ABI, if provided.

  • args (Optional[dict]) – The arguments to pass to the contract method.

  • amount (Optional[Decimal]) – The amount of native asset to send to a payable contract method.

  • asset_id (Optional[str]) – The asset ID to send to the contract.

Returns:

The new ContractInvocation object.

Return type:

ContractInvocation

classmethod list(wallet_id, address_id)

List Contract Invocations.

Parameters:
  • wallet_id (str) – The wallet ID.

  • address_id (str) – The address ID.

Returns:

An iterator of ContractInvocation objects.

Return type:

Iterator[ContractInvocation]

property method: str

Get the method being invoked in the contract.

Returns:

The method being invoked.

Return type:

str

property network_id: str

Get the network ID of the contract invocation.

Returns:

The network ID.

Return type:

str

reload()

Reload the Contract Invocation model with the latest version from the server.

Returns:

The updated ContractInvocation object.

Return type:

ContractInvocation

sign(key)

Sign the contract invocation transaction with the given key.

Parameters:

key (LocalAccount) – The key to sign the contract invocation with.

Returns:

The signed ContractInvocation object.

Return type:

ContractInvocation

Raises:

ValueError – If the key is not a LocalAccount.

property status: str

Get the status of the contract invocation.

Returns:

The status.

Return type:

str

property transaction: Transaction | None

Get the transaction associated with the contract invocation.

Returns:

The transaction.

Return type:

Transaction

property transaction_hash: str

Get the transaction hash of the contract invocation.

Returns:

The transaction hash.

Return type:

str

Get the link to the transaction on the blockchain explorer.

Returns:

The transaction link.

Return type:

str

wait(interval_seconds=0.2, timeout_seconds=20)

Wait until the contract invocation is signed or fails by polling the server.

Parameters:
  • interval_seconds (float) – The interval at which to poll the server.

  • timeout_seconds (float) – The maximum time to wait before timing out.

Returns:

The completed contract invocation.

Return type:

ContractInvocation

Raises:

TimeoutError – If the invocation takes longer than the given timeout.

property wallet_id: str

Get the wallet ID of the contract invocation.

Returns:

The wallet ID.

Return type:

str

cdp.crypto_amount module

class cdp.crypto_amount.CryptoAmount(amount, asset, asset_id=None)

Bases: object

A representation of a CryptoAmount that includes the amount and asset.

property amount: Decimal

Get the amount of the Asset.

Returns:

The amount of the Asset.

Return type:

Decimal

property asset: Asset

Get the Asset.

Returns:

The Asset.

Return type:

Asset

property asset_id: str

Get the Asset ID.

Returns:

The Asset ID.

Return type:

str

classmethod from_model(crypto_amount_model)

Convert a CryptoAmount model to a CryptoAmount.

Parameters:

crypto_amount_model (CryptoAmountModel) – The crypto amount from the API.

Returns:

The converted CryptoAmount object.

Return type:

CryptoAmount

classmethod from_model_and_asset_id(crypto_amount_model, asset_id)

Convert a CryptoAmount model and asset ID to a CryptoAmount.

This can be used to specify a non-primary denomination that we want the amount to be converted to.

Parameters:
  • crypto_amount_model (CryptoAmountModel) – The crypto amount from the API.

  • asset_id (str) – The Asset ID of the denomination we want returned.

Returns:

The converted CryptoAmount object.

Return type:

CryptoAmount

to_atomic_amount()

Convert the amount to atomic units.

Returns:

The amount in atomic units.

Return type:

Decimal

cdp.errors module

exception cdp.errors.AddressCannotSignError(msg='Address cannot sign transaction without private key loaded')

Bases: Exception

An error raised when an address attempts to sign a transaction without a private key.

exception cdp.errors.AlreadyExistsError(err, code=None, message=None, correlation_id=None, unhandled=False)

Bases: ApiError

Exception raised when a resource already exists.

exception cdp.errors.AlreadySignedError(msg='Resource already signed')

Bases: Exception

An error raised when a resource is already signed.

exception cdp.errors.ApiError(err, code=None, message=None, correlation_id=None, unhandled=False)

Bases: Exception

A wrapper for API exceptions to provide more context.

property api_code: str | None

Get the API error code.

Returns:

The API error code.

Return type:

str | None

property api_message: str | None

Get the API error message.

Returns:

The API error message.

Return type:

str | None

property correlation_id: str | None

Get the correlation ID.

Returns:

The correlation ID.

Return type:

str | None

classmethod from_error(err)

Create an ApiError from an ApiException.

Parameters:

err (ApiException) – The ApiException to create an ApiError from.

Returns:

The API Error.

Return type:

ApiError

Raises:

ValueError – If the argument is not an ApiException.

property handled: bool

Get whether the error is handled.

Returns:

True if the error is handled, False otherwise.

Return type:

bool

property http_code: int

Get the HTTP status code.

Returns:

The HTTP status code.

Return type:

int

exception cdp.errors.FaucetLimitReachedError(err, code=None, message=None, correlation_id=None, unhandled=False)

Bases: ApiError

Exception raised when the faucet limit is reached.

exception cdp.errors.InsufficientFundsError(expected, exact, msg='Insufficient funds')

Bases: Exception

An error raised when an operation is attempted with insufficient funds.

exception cdp.errors.InternalError(err, code=None, message=None, correlation_id=None, unhandled=False)

Bases: ApiError

Exception raised for internal server errors.

exception cdp.errors.InvalidAPIKeyFormatError(message='Invalid API key format')

Bases: Exception

Exception raised for errors in the format of the API key.

exception cdp.errors.InvalidAddressError(err, code=None, message=None, correlation_id=None, unhandled=False)

Bases: ApiError

Exception raised for invalid address.

exception cdp.errors.InvalidAddressIDError(err, code=None, message=None, correlation_id=None, unhandled=False)

Bases: ApiError

Exception raised for invalid address ID.

exception cdp.errors.InvalidAmountError(err, code=None, message=None, correlation_id=None, unhandled=False)

Bases: ApiError

Exception raised for invalid amount.

exception cdp.errors.InvalidAssetIDError(err, code=None, message=None, correlation_id=None, unhandled=False)

Bases: ApiError

Exception raised for invalid asset ID.

exception cdp.errors.InvalidConfigurationError(message='Invalid configuration provided')

Bases: Exception

Exception raised for errors in the configuration of the Coinbase SDK.

exception cdp.errors.InvalidDestinationError(err, code=None, message=None, correlation_id=None, unhandled=False)

Bases: ApiError

Exception raised for invalid destination.

exception cdp.errors.InvalidLimitError(err, code=None, message=None, correlation_id=None, unhandled=False)

Bases: ApiError

Exception raised for invalid page limit.

exception cdp.errors.InvalidNetworkIDError(err, code=None, message=None, correlation_id=None, unhandled=False)

Bases: ApiError

Exception raised for invalid network ID.

exception cdp.errors.InvalidPageError(err, code=None, message=None, correlation_id=None, unhandled=False)

Bases: ApiError

Exception raised for invalid page token.

exception cdp.errors.InvalidSignedPayloadError(err, code=None, message=None, correlation_id=None, unhandled=False)

Bases: ApiError

Exception raised for invalid signed payload.

exception cdp.errors.InvalidTransferIDError(err, code=None, message=None, correlation_id=None, unhandled=False)

Bases: ApiError

Exception raised for invalid transfer ID.

exception cdp.errors.InvalidTransferStatusError(err, code=None, message=None, correlation_id=None, unhandled=False)

Bases: ApiError

Exception raised for invalid transfer status.

exception cdp.errors.InvalidWalletError(err, code=None, message=None, correlation_id=None, unhandled=False)

Bases: ApiError

Exception raised for invalid wallet.

exception cdp.errors.InvalidWalletIDError(err, code=None, message=None, correlation_id=None, unhandled=False)

Bases: ApiError

Exception raised for invalid wallet ID.

exception cdp.errors.MalformedRequestError(err, code=None, message=None, correlation_id=None, unhandled=False)

Bases: ApiError

Exception raised for malformed requests.

exception cdp.errors.NetworkFeatureUnsupportedError(err, code=None, message=None, correlation_id=None, unhandled=False)

Bases: ApiError

Exception raised when a network feature is unsupported.

exception cdp.errors.NotFoundError(err, code=None, message=None, correlation_id=None, unhandled=False)

Bases: ApiError

Exception raised when a requested resource is not found.

exception cdp.errors.ResourceExhaustedError(err, code=None, message=None, correlation_id=None, unhandled=False)

Bases: ApiError

Exception raised when a resource is exhausted.

exception cdp.errors.TransactionNotSignedError(msg='Transaction must be signed')

Bases: Exception

An error raised when a transaction is not signed.

exception cdp.errors.UnauthorizedError(err, code=None, message=None, correlation_id=None, unhandled=False)

Bases: ApiError

Exception raised for unauthorized access to Coinbase API endpoints.

exception cdp.errors.UnimplementedError(err, code=None, message=None, correlation_id=None, unhandled=False)

Bases: ApiError

Exception raised for unimplemented features in the Coinbase SDK.

exception cdp.errors.UnsupportedAssetError(err, code=None, message=None, correlation_id=None, unhandled=False)

Bases: ApiError

Exception raised for unsupported assets.

cdp.faucet_transaction module

class cdp.faucet_transaction.FaucetTransaction(model)

Bases: object

A class representing a faucet transaction.

property address_id: str

Get the address.

Returns:

The address.

Return type:

str

property network_id: str

Get the network ID.

Returns:

The network ID.

Return type:

str

reload()

Reload the faucet transaction.

Return type:

FaucetTransaction

Returns:

None

property status: str

Get the faucet transaction status.

Returns:

The faucet transaction status.

Return type:

str

property transaction: Transaction

Get the Faucet transaction.

property transaction_hash: str

Get the transaction hash.

Returns:

The transaction hash.

Return type:

str

Get the transaction link.

Returns:

The transaction link.

Return type:

str

wait(interval_seconds=0.2, timeout_seconds=20)

Wait for the faucet transaction to complete.

Parameters:
  • interval_seconds (float) – The interval seconds.

  • timeout_seconds (float) – The timeout seconds.

Returns:

The faucet transaction.

Return type:

FaucetTransaction

cdp.fiat_amount module

class cdp.fiat_amount.FiatAmount(amount, currency)

Bases: object

A representation of a FiatAmount that includes the amount and currency.

property amount: Decimal

Get the amount in the fiat currency.

Returns:

The amount in the fiat currency.

Return type:

Decimal

property currency: str

Get the currency code.

Returns:

The currency code.

Return type:

str

classmethod from_model(fiat_amount_model)

Convert a FiatAmount model to a FiatAmount.

Parameters:

fiat_amount_model (FiatAmountModel) – The fiat amount from the API.

Returns:

The converted FiatAmount object.

Return type:

FiatAmount

cdp.fund_operation module

class cdp.fund_operation.FundOperation(model)

Bases: object

A representation of a Fund Operation.

class Status(value)

Bases: Enum

Fund Operation status constants.

COMPLETE = 'complete'
FAILED = 'failed'
PENDING = 'pending'
classmethod terminal_states()

Get the terminal states.

Returns:

The terminal states.

Return type:

List[Status]

property address_id: str

Get the Address ID.

property amount: CryptoAmount

Get the crypto amount.

property asset: Asset

Get the Asset.

property buy_fee: dict

Get the buy fee.

Returns:

The buy fee information.

Return type:

dict

classmethod create(wallet_id, address_id, amount, asset_id, network_id, quote=None)

Create a new Fund Operation.

Parameters:
  • wallet_id (str) – The Wallet ID

  • address_id (str) – The Address ID

  • amount (Decimal) – The amount of the Asset

  • asset_id (str) – The Asset ID

  • network_id (str) – The Network ID

  • quote (Optional[FundQuote]) – The optional Fund Quote

Returns:

The new FundOperation object

Return type:

FundOperation

property fiat_amount: FiatAmount

Get the fiat amount.

property fiat_currency: str

Get the fiat currency.

property id: str

Get the Fund Operation ID.

classmethod list(wallet_id, address_id)

List fund operations.

Parameters:
  • wallet_id (str) – The wallet ID

  • address_id (str) – The address ID

Returns:

An iterator of fund operation objects

Return type:

Iterator[FundOperation]

property network_id: str

Get the Network ID.

reload()

Reload the fund operation from the server.

Returns:

The updated fund operation.

Return type:

FundOperation

property status: Status

Get the status.

terminal_state()

Check if the operation is in a terminal state.

Return type:

bool

property transfer_fee: CryptoAmount

Get the transfer fee.

Returns:

The transfer fee.

Return type:

CryptoAmount

wait(interval_seconds=0.2, timeout_seconds=20)

Wait for the fund operation to complete.

Parameters:
  • interval_seconds (float) – The interval between checks

  • timeout_seconds (float) – The maximum time to wait

Returns:

The completed fund operation

Return type:

FundOperation

Raises:

TimeoutError – If the operation takes too long

property wallet_id: str

Get the Wallet ID.

cdp.fund_quote module

class cdp.fund_quote.FundQuote(model)

Bases: object

A representation of a Fund Operation Quote.

property address_id: str

Get the Address ID.

Returns:

The Address ID.

Return type:

str

property amount: CryptoAmount

Get the crypto amount.

Returns:

The crypto amount.

Return type:

CryptoAmount

property asset: Asset

Get the Asset.

Returns:

The Asset.

Return type:

Asset

property buy_fee: dict

Get the buy fee.

Returns:

The buy fee information.

Return type:

dict

classmethod create(wallet_id, address_id, amount, asset_id, network_id)

Create a new Fund Operation Quote.

Parameters:
  • wallet_id (str) – The Wallet ID

  • address_id (str) – The Address ID

  • amount (Decimal) – The amount of the Asset

  • asset_id (str) – The Asset ID

  • network_id (str) – The Network ID

Returns:

The new FundQuote object

Return type:

FundQuote

execute()

Execute the fund quote to create a fund operation.

Returns:

The created fund operation.

Return type:

FundOperation

property fiat_amount: FiatAmount

Get the fiat amount.

Returns:

The fiat amount.

Return type:

Decimal

property fiat_currency: str

Get the fiat currency.

Returns:

The fiat currency.

Return type:

str

property id: str

Get the Fund Quote ID.

Returns:

The Fund Quote ID.

Return type:

str

property network_id: str

Get the Network ID.

Returns:

The Network ID.

Return type:

str

property transfer_fee: CryptoAmount

Get the transfer fee.

Returns:

The transfer fee.

Return type:

CryptoAmount

property wallet_id: str

Get the Wallet ID.

Returns:

The Wallet ID.

Return type:

str

cdp.hash_utils module

cdp.hash_utils.hash_message(message_text)

Hashes a message according to EIP-191 and returns the hash as a 0x-prefixed hexadecimal string.

This function prefixes the message with the standard Ethereum message prefix and hashes it using Keccak-256.

Parameters:

message_text (str) – The message to hash.

Returns:

The 0x-prefixed hexadecimal string of the message hash.

Return type:

str

cdp.hash_utils.hash_typed_data_message(typed_data)

Hashes typed data according to EIP-712 and returns the hash as a 0x-prefixed hexadecimal string.

This function encodes the typed data as per EIP-712 and hashes it using Keccak-256.

Parameters:

typed_data (dict) – The typed data to hash, following the EIP-712 specification.

Returns:

The 0x-prefixed hexadecimal string of the typed data hash.

Return type:

str

cdp.historical_balance module

class cdp.historical_balance.HistoricalBalance(amount, asset, block_height, block_hash)

Bases: object

A class representing a balance.

property amount: Decimal

Get the amount.

Returns:

The amount.

Return type:

Decimal

property asset: Asset

Get the asset.

Returns:

The asset.

Return type:

Asset

property block_hash: str

Get the block hash.

Returns:

The block hash.

Return type:

str

property block_height: str

Get the block height.

Returns:

The block height.

Return type:

str

classmethod from_model(model)

Create a Balance instance from a model.

Parameters:
  • model (BalanceModel) – The model representing the balance.

  • asset_id (Optional[str]) – The asset ID.

Returns:

The Balance instance.

Return type:

Balance

classmethod list(network_id, address_id, asset_id)

List historical balances of an address of an asset.

Parameters:
  • network_id (str) – The ID of the network to list historical balance for.

  • address_id (str) – The ID of the address to list historical balance for.

  • asset_id (str) – The asset ID to list historical balance.

Returns:

An iterator of HistoricalBalance objects.

Return type:

Iterator[Transaction]

Raises:

Exception – If there’s an error listing the historical_balances.

cdp.payload_signature module

class cdp.payload_signature.PayloadSignature(model)

Bases: object

A representation of a Payload Signature.

class Status(value)

Bases: Enum

Enumeration of Payload Signature statuses.

FAILED = 'failed'
PENDING = 'pending'
SIGNED = 'signed'
classmethod terminal_states()

Get the terminal states.

Returns:

The terminal states.

Return type:

List[str]

property address_id: str

Get the address ID.

Returns:

The address ID.

Return type:

str

classmethod create(wallet_id, address_id, unsigned_payload, signature=None)

Create a payload signature.

Parameters:
  • wallet_id (str) – The wallet ID.

  • address_id (str) – The address ID.

  • unsigned_payload (str) – The unsigned payload.

  • signature (Optional[str]) – The signature.

Returns:

The payload signature.

Return type:

PayloadSignature

Raises:

Exception – If there’s an error creating the payload signature..

classmethod list(wallet_id, address_id)

List payload signatures.

Parameters:
  • wallet_id (str) – The wallet ID.

  • address_id (str) – The address ID.

Returns:

An iterator of payload signatures.

Return type:

Iterator[Payload]

Raises:

Exception – If there’s an error listing the payload signatures.

property payload_signature_id: str

Get the payload signature ID.

Returns:

The payload signature ID.

Return type:

str

reload()

Reload the payload signature.

Return type:

None

property signature: str

Get the signature.

Returns:

The signature.

Return type:

str

property status: Status

Get the status.

Returns:

The status.

Return type:

PayloadSignature.Status

property terminal_state: bool

Check if the Transaction is in a terminal state.

Returns:

Whether the paylaod signature is in a terminal state.

Return type:

bool

property unsigned_payload: str

Get the unsigned payload.

Returns:

The unsigned payload.

Return type:

str

wait(interval_seconds=0.2, timeout_seconds=20)

Wait for the payload signature to complete.

Parameters:
  • interval_seconds (float) – The interval seconds.

  • timeout_seconds (float) – The timeout seconds.

Returns:

The payload signature.

Return type:

PayloadSignature

property wallet_id: str

Get the wallet ID.

Returns:

The wallet ID.

Return type:

str

cdp.smart_contract module

class cdp.smart_contract.SmartContract(model)

Bases: object

A representation of a SmartContract on the blockchain.

class MultiTokenContractOptions(uri)

Bases: dict

Options for multi-token contracts (ERC1155).

class NFTContractOptions(name, symbol, base_uri)

Bases: dict

Options for NFT contracts (ERC721).

class TokenContractOptions(name, symbol, total_supply)

Bases: dict

Options for token contracts (ERC20).

class Type(value)

Bases: Enum

Enumeration of SmartContract types.

ERC1155 = 'erc1155'
ERC20 = 'erc20'
ERC721 = 'erc721'
property abi: dict[str, Any]

Get the ABI of the smart contract.

Returns:

The ABI as a JSON object.

broadcast()

Broadcast the smart contract deployment to the network.

Return type:

SmartContract

Returns:

The broadcasted SmartContract object.

Raises:

ValueError – If the smart contract deployment is not signed.

property contract_address: str

Get the contract address of the smart contract.

Returns:

The contract address.

classmethod create(wallet_id, address_id, type, options)

Create a new SmartContract object.

Parameters:
  • wallet_id (str) – The ID of the wallet that will deploy the smart contract.

  • address_id (str) – The ID of the address that will deploy the smart contract.

  • type (Type) – The type of the smart contract (ERC20, ERC721, or ERC1155).

  • options (TokenContractOptions | NFTContractOptions | MultiTokenContractOptions) – The options of the smart contract.

Return type:

SmartContract

Returns:

The created smart contract.

Raises:

ValueError – If the options type is unsupported.

property deployer_address: str

Get the deployer address of the smart contract.

Returns:

The deployer address.

property network_id: str

Get the network ID of the smart contract.

Returns:

The network ID.

property options: TokenContractOptions | NFTContractOptions | MultiTokenContractOptions

Get the options of the smart contract.

Returns:

The smart contract options as a higher-level options class.

Raises:

ValueError – If the smart contract type is unknown or if options are not set.

classmethod read(network_id, contract_address, method, abi=None, args=None)

Read data from a smart contract.

Parameters:
  • network_id (str) – The ID of the network.

  • contract_address (str) – The address of the smart contract.

  • method (str) – The method to call on the smart contract.

  • abi (Optional[list[dict]]) – The ABI of the smart contract.

  • args (Optional[dict]) – The arguments to pass to the method.

Return type:

SmartContract

Returns:

The data read from the smart contract.

reload()

Reload the SmartContract model with the latest data from the server.

Return type:

SmartContract

Returns:

The updated SmartContract object.

sign(key)

Sign the smart contract deployment with the given key.

Parameters:

key (LocalAccount) – The key to sign the smart contract deployment with.

Return type:

SmartContract

Returns:

The signed SmartContract object.

Raises:

ValueError – If the key is not a LocalAccount.

property smart_contract_id: str

Get the smart contract ID.

Returns:

The smart contract ID.

property transaction: Transaction | None

Get the transaction associated with the smart contract deployment.

Returns:

The transaction.

Return type:

Transaction

property type: Type

Get the type of the smart contract.

Returns:

The smart contract type.

Raises:

ValueError – If the smart contract type is unknown.

wait(interval_seconds=0.2, timeout_seconds=10)

Wait until the smart contract deployment is confirmed on the network or fails onchain.

Parameters:
  • interval_seconds (float) – The interval to check the status of the smart contract deployment.

  • timeout_seconds (float) – The maximum time to wait for the smart contract deployment to be confirmed.

Return type:

SmartContract

Returns:

The SmartContract object in a terminal state.

Raises:

TimeoutError – If the smart contract deployment times out.

property wallet_id: str

Get the wallet ID that deployed the smart contract.

Returns:

The wallet ID.

cdp.sponsored_send module

class cdp.sponsored_send.SponsoredSend(model)

Bases: object

A representation of an onchain Sponsored Send.

class Status(value)

Bases: Enum

Enumeration of SponsoredSend statuses.

COMPLETE = 'complete'
FAILED = 'failed'
PENDING = 'pending'
SIGNED = 'signed'
SUBMITTED = 'submitted'
classmethod terminal_states()

Get the terminal states.

Returns:

The terminal states.

Return type:

List[str]

sign(key)

Sign the Transaction with the provided key.

Parameters:

key (LocalAccount) – The Ethereum account to sign with.

Returns:

The hex-encoded signed payload.

Return type:

str

Raises:

ValueError – If the transaction is already signed.

property signature: str | None

Get the signature of the typed data.

Returns:

The signature, if available.

Return type:

Optional[str]

property signed: bool

Check if the Transaction has been signed.

Returns:

True if signed, False otherwise.

Return type:

bool

property status: Status

Get the status of the Transaction.

Returns:

The current status.

Return type:

Status

property terminal_state: bool

Check if the Sponsored Send is in a terminal state.

Returns:

True if in a terminal state, False otherwise.

Return type:

bool

property transaction_hash: str

Get the Transaction Hash of the Transaction.

Returns:

The Transaction Hash.

Return type:

str

Get the link to the transaction on the blockchain explorer.

Returns:

The link to the transaction.

Return type:

str

property typed_data_hash: str

Get the Keccak256 hash of the typed data.

Returns:

The Keccak256 hash of the typed data.

Return type:

str

cdp.trade module

class cdp.trade.Trade(model)

Bases: object

A class representing a trade.

property address_id: str

Get the address ID.

Returns:

The address ID.

Return type:

str

property approve_transaction: Transaction | None

Get the approve transaction.

broadcast()

Broadcast the trade.

Returns:

The broadcasted trade.

Return type:

Trade

Raises:

TransactionNotSignedError – If the trade is not signed.

static create(address_id, from_asset_id, to_asset_id, amount, network_id, wallet_id)

Create a new trade.

Parameters:
  • address_id (str) – The ID of the address to use for the trade.

  • from_asset_id (str) – The ID of the asset to trade.

  • to_asset_id (str) – The ID of the asset to receive from the trade.

  • amount (Decimal) – The amount to trade.

  • network_id (str) – The ID of the network to use for the trade.

  • wallet_id (str) – The ID of the wallet to use for the trade.

Returns:

The created trade.

Return type:

Trade

property from_amount: Decimal

Get the from amount.

Returns:

The from amount.

Return type:

Decimal

property from_asset_id: str

Get the from asset ID.

Returns:

The from asset ID.

Return type:

str

classmethod list(wallet_id, address_id)

List all trades for an address.

Parameters:
  • wallet_id (str) – The ID of the wallet to list trades for.

  • address_id (str) – The ID of the address to list trades for.

Returns:

An iterator of trade objects.

Return type:

Iterator[Trade]

property network_id: str

Get the network ID.

Returns:

The network ID.

Return type:

str

reload()

Reload the trade.

Return type:

None

property status: str

Get the status.

Returns:

The status.

Return type:

str

property to_amount: Decimal

Get the to amount.

Returns:

The to amount.

Return type:

Decimal

property to_asset_id: str

Get the to asset ID.

Returns:

The to asset ID.

Return type:

str

property trade_id: str

Get the trade ID.

Returns:

The trade ID.

Return type:

str

property transaction: Transaction

Get the trade transaction.

wait(interval_seconds=0.2, timeout_seconds=20)

Wait for the trade to complete.

Parameters:
  • interval_seconds (float) – The interval seconds.

  • timeout_seconds (float) – The timeout seconds.

Returns:

The trade.

Return type:

Trade

property wallet_id: str

Get the wallet ID.

Returns:

The wallet ID.

Return type:

str

cdp.transaction module

class cdp.transaction.Transaction(model)

Bases: object

A representation of an onchain Transaction.

class Status(value)

Bases: Enum

Enumeration of Transaction statuses.

BROADCAST = 'broadcast'
COMPLETE = 'complete'
FAILED = 'failed'
PENDING = 'pending'
SIGNED = 'signed'
UNSPECIFIED = 'unspecified'
classmethod terminal_states()

Get the terminal states.

Returns:

The terminal states.

Return type:

List[str]

property block_hash: str

Get the block hash of which the Transaction is recorded.

property block_height: str

Get the block height of which the Transaction is recorded.

property content: str

Get the content of the transaction.

property from_address_id: str

Get the from address ID.

classmethod list(network_id, address_id)

List transactions of the address.

Parameters:
  • network_id (str) – The ID of the network to list transaction for.

  • address_id (str) – The ID of the address to list transaction for.

Returns:

An iterator of Transaction objects.

Return type:

Iterator[Transaction]

Raises:

Exception – If there’s an error listing the transactions.

property network_id: str

Get the Network ID of the Transaction.

property raw: DynamicFeeTransaction

Get the underlying raw transaction.

sign(key)

Sign the Transaction with the provided key.

Parameters:

key (LocalAccount) – The Ethereum account to sign with.

Returns:

The hex-encoded signed payload.

Return type:

str

Raises:

ValueError – If the transaction is already signed.

property signature: str

Get the signature of the Transaction.

property signed: bool

Check if the Transaction has been signed.

property signed_payload: str

Get the signed payload.

property status: Status

Get the status.

property terminal_state: bool

Check if the Transaction is in a terminal state.

property to_address_id: str

Get the to address ID.

property transaction_hash: str

Get the transaction hash.

Get the transaction link.

property unsigned_payload: str

Get the unsigned payload.

cdp.transfer module

class cdp.transfer.Transfer(model)

Bases: object

A class representing a transfer.

property amount: Decimal

Get the amount of the asset for the Transfer.

property asset: Asset

Get the Asset of the Transfer.

property asset_id: str

Get the Asset ID of the Transfer.

broadcast()

Broadcast the Transfer to the Network.

Returns:

The Transfer object.

Return type:

Transfer

Raises:

TransactionNotSignedError – If the Transfer is not signed.

classmethod create(address_id, amount, asset_id, destination, network_id, wallet_id, gasless=False)

Create a transfer.

Parameters:
  • address_id (str) – The address ID.

  • amount (Decimal) – The amount.

  • asset_id (str) – The asset ID.

  • destination (Union[Address, Wallet, str]) – The destination.

  • network_id (str) – The network ID.

  • wallet_id (str) – The wallet ID.

  • gasless (bool) – Whether to use gasless.

Returns:

The transfer.

Return type:

Transfer

property destination_address_id: str

Get the Destination Address ID of the Transfer.

property from_address_id: str

Get the from address ID.

Returns:

The from address ID.

Return type:

str

classmethod list(wallet_id, address_id)

List transfers.

Parameters:
  • wallet_id (str) – The wallet ID.

  • address_id (str) – The address ID.

Returns:

An iterator of transfer objects.

Return type:

Iterator[Transfer]

Raises:

Exception – If there’s an error listing the transfers.

property network_id: str

Get the Network ID of the Transfer.

reload()

Reload the transfer.

Return type:

None

Returns:

None

property send_tx_delegate: SponsoredSend | Transaction | None

Get the appropriate delegate for the transfer (SponsoredSend or Transaction).

sign(key)

Sign the Transfer with the given key.

Parameters:

key (LocalAccount) – The key to sign the Transfer with.

Returns:

The Transfer object.

Return type:

Transfer

Raises:

ValueError – If the key is not a LocalAccount.

property sponsored_send: SponsoredSend | None

Get the SponsoredSend of the Transfer, if the transfer is gasless.

property status: str

Get the status.

Returns:

The status.

Return type:

str

property terminal_state: bool

Check if the Transfer is in a terminal state.

property transaction: Transaction | None

Get the Transfer transaction.

property transaction_hash: str

Get the Transaction Hash of the Transfer.

Get the link to the transaction on the blockchain explorer.

property transfer_id: str

Get the transfer ID.

Returns:

The transfer ID.

Return type:

str

wait(interval_seconds=0.2, timeout_seconds=20)

Wait for the transfer to complete.

Parameters:
  • interval_seconds (float) – The interval seconds.

  • timeout_seconds (float) – The timeout seconds.

Returns:

The transfer.

Return type:

Transfer

property wallet_id: str

Get the wallet ID.

Returns:

The wallet ID.

Return type:

str

cdp.wallet module

class cdp.wallet.Wallet(model, seed=None)

Bases: object

A class representing a wallet.

MAX_ADDRESSES: int = 20

The maximum number of addresses that can be associated with a wallet.

property addresses: list[WalletAddress]

Get the addresses of the wallet.

Returns:

The addresses of the wallet.

Return type:

List[WalletAddress]

balance(asset_id)

Get the balance of a specific asset for the default address.

Parameters:

asset_id (str) – The ID of the asset to check the balance for.

Returns:

The balance of the specified asset.

Return type:

Any

Raises:

ValueError – If the default address does not exist.

balances()

List balances of the address.

Returns:

The balances of the address, keyed by asset ID. Ether balances are denominated in ETH.

Return type:

BalanceMap

Raises:

ValueError – If the default address does not exist.

property can_sign: bool

Check if the wallet can sign transactions.

Returns:

True if the wallet can sign, False otherwise.

Return type:

bool

classmethod create(network_id='base-sepolia', interval_seconds=0.2, timeout_seconds=20)

Create a new wallet.

Parameters:
  • network_id (str) – The network ID of the wallet. Defaults to “base-sepolia”.

  • interval_seconds (float) – The interval between checks in seconds. Defaults to 0.2.

  • timeout_seconds (float) – The maximum time to wait for the server signer to be active. Defaults to 20.

Returns:

The created wallet object.

Return type:

Wallet

Raises:

Exception – If there’s an error creating the wallet.

create_address()

Create a new address for the wallet.

Returns:

The created address object.

Return type:

WalletAddress

Raises:

Exception – If there’s an error creating the address.

create_webhook(notification_uri)

Create a new webhook for the wallet.

Parameters:

notification_uri (str) – The notification URI of the webhook.

Returns:

The created webhook object. It can be used to monitor activities happening in the wallet. When they occur, webhook will make a request to the specified URI.

Return type:

Webhook

Raises:

Exception – If there’s an error creating the webhook.

property default_address: WalletAddress | None

Get the default address of the wallet.

Returns:

The default address object, or None if not set.

Return type:

Optional[WalletAddress]

deploy_multi_token(uri)

Deploy a multi-token smart contract.

Parameters:

uri (str) – The URI for the multi-token contract.

Returns:

The deployed smart contract.

Return type:

SmartContract

Raises:

ValueError – If the default address does not exist.

deploy_nft(name, symbol, base_uri)

Deploy an NFT smart contract.

Parameters:
  • name (str) – The name of the NFT.

  • symbol (str) – The symbol of the NFT.

  • base_uri (str) – The base URI for the NFT.

Returns:

The deployed smart contract.

Return type:

SmartContract

Raises:

ValueError – If the default address does not exist.

deploy_token(name, symbol, total_supply)

Deploy a token smart contract.

Parameters:
  • name (str) – The name of the token.

  • symbol (str) – The symbol of the token.

  • total_supply (Union[Number, Decimal, str]) – The total supply of the token.

Returns:

The deployed smart contract.

Return type:

SmartContract

Raises:

ValueError – If the default address does not exist.

export_data()

Export the wallet’s data.

Returns:

The wallet’s data.

Return type:

WalletData

Raises:

ValueError – If the wallet does not have a seed loaded.

faucet(asset_id=None)

Request faucet funds.

Parameters:

asset_id (Optional[str]) – The asset ID. Defaults to None.

Returns:

The faucet transaction object.

Return type:

FaucetTransaction

Raises:

ValueError – If the default address does not exist.

classmethod fetch(wallet_id)

Fetch a wallet by its ID.

Parameters:

wallet_id (str) – The ID of the wallet to retrieve.

Returns:

The retrieved wallet object.

Return type:

Wallet

Raises:

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

fund(amount, asset_id)

Fund the wallet from your account on the Coinbase Platform.

Parameters:
  • amount (Union[Number, Decimal, str]) – The amount of the Asset to fund the wallet with.

  • asset_id (str) – The ID of the Asset to fund with. For Ether, ‘eth’, ‘gwei’, and ‘wei’ are supported.

Returns:

The created fund operation object.

Return type:

FundOperation

Raises:

ValueError – If the default address does not exist.

property id: str

Get the ID of the wallet.

Returns:

The ID of the wallet.

Return type:

str

classmethod import_data(data)

Import a wallet from previously exported wallet data.

Parameters:

data (WalletData) – The wallet data to import.

Returns:

The imported wallet.

Return type:

Wallet

Raises:

Exception – If there’s an error getting the wallet.

invoke_contract(contract_address, method, abi=None, args=None, amount=None, asset_id=None)

Invoke a method on the specified contract address, with the given ABI and arguments.

Parameters:
  • contract_address (str) – The address of the contract to invoke.

  • method (str) – The name of the method to call on the contract.

  • abi (Optional[list[dict]]) – The ABI of the contract, if provided.

  • args (Optional[dict]) – The arguments to pass to the method.

  • amount (Optional[Union[Number, Decimal, str]]) – The amount to send with the invocation, if applicable.

  • asset_id (Optional[str]) – The asset ID associated with the amount, if applicable.

Returns:

The contract invocation object.

Return type:

ContractInvocation

Raises:

ValueError – If the default address does not exist.

classmethod list()

List wallets.

Returns:

An iterator of wallet objects.

Return type:

Iterator[Wallet]

Raises:

Exception – If there’s an error listing the wallets.

load_seed(file_path)

Load the wallet seed from a file.

Parameters:

file_path (str) – The path to the file containing the seed data.

Raises:

ValueError – If the file does not contain seed data for this wallet or if decryption fails.

Return type:

None

property network_id: str

Get the network ID of the wallet.

Returns:

The network ID of the wallet.

Return type:

str

quote_fund(amount, asset_id)

Get a quote for funding the wallet from your Coinbase platform account.

Parameters:
  • amount (Union[Number, Decimal, str]) – The amount to fund.

  • asset_id (str) – The ID of the Asset to fund with. For Ether, ‘eth’, ‘gwei’, and ‘wei’ are supported.

Returns:

The fund quote object.

Return type:

FundQuote

Raises:

ValueError – If the default address does not exist.

reload()

Reload the wallet model from the API.

Return type:

None

Returns:

None

save_seed(file_path, encrypt=False)

Save the wallet seed to a file.

Parameters:
  • file_path (str) – The path to the file where the seed will be saved.

  • encrypt (Optional[bool]) – Whether to encrypt the seed before saving. Defaults to False.

Raises:

ValueError – If the wallet does not have a seed loaded.

Return type:

None

property server_signer_status: str

Get the server signer status of the wallet.

Returns:

The server signer status of the wallet.

Return type:

str

sign_payload(unsigned_payload)

Sign the given unsigned payload.

Parameters:

unsigned_payload (str) – The unsigned payload.

Returns:

The payload signature object.

Return type:

PayloadSignature

trade(amount, from_asset_id, to_asset_id)

Trade funds from the wallet address.

Parameters:
  • amount (Union[Number, Decimal, str]) – The amount to trade.

  • from_asset_id (str) – The asset ID to trade from.

  • to_asset_id (str) – The asset ID to trade to.

Returns:

The trade object.

Return type:

Trade

Raises:

ValueError – If the default address does not exist.

transfer(amount, asset_id, destination, gasless=False)

Transfer funds from the wallet.

Parameters:
  • amount (Union[Number, Decimal, str]) – The amount of funds to transfer.

  • asset_id (str) – The ID of the asset to transfer.

  • destination (Union[Address, 'Wallet', str]) – The destination for the transfer.

  • gasless (bool) – Whether the transfer should be gasless. Defaults to False.

Returns:

The result of the transfer operation.

Return type:

Any

Raises:

ValueError – If the default address does not exist.

cdp.wallet_address module

class cdp.wallet_address.WalletAddress(model, key=None)

Bases: Address

A class representing a wallet address.

property can_sign: bool

Get whether the address can sign.

Returns:

Whether the address can sign.

Return type:

bool

deploy_multi_token(uri)

Deploy a multi-token smart contract.

Parameters:

uri (str) – The URI for the multi-token contract.

Returns:

The deployed smart contract.

Return type:

SmartContract

deploy_nft(name, symbol, base_uri)

Deploy an NFT smart contract.

Parameters:
  • name (str) – The name of the NFT.

  • symbol (str) – The symbol of the NFT.

  • base_uri (str) – The base URI for the NFT.

Returns:

The deployed smart contract.

Return type:

SmartContract

deploy_token(name, symbol, total_supply)

Deploy a token smart contract.

Parameters:
  • name (str) – The name of the token.

  • symbol (str) – The symbol of the token.

  • total_supply (Union[Number, Decimal, str]) – The total supply of the token.

Returns:

The deployed smart contract.

Return type:

SmartContract

export()

Export the wallet address’s private key as a hex string.

Returns:

The wallet address’s private key as a hex string.

Return type:

str

Raises:

ValueError – If the wallet address does not have a private key.

fund(amount, asset_id)

Fund the address from your account on the Coinbase Platform.

Parameters:
  • amount (Union[Number, Decimal, str]) – The amount of the Asset to fund the wallet with.

  • asset_id (str) – The ID of the Asset to fund with. For Ether, ‘eth’, ‘gwei’, and ‘wei’ are supported.

Returns:

The created fund operation object.

Return type:

FundOperation

invoke_contract(contract_address, method, abi=None, args=None, amount=None, asset_id=None)

Invoke a method on the specified contract address, with the given ABI and arguments.

Parameters:
  • contract_address (str) – The address of the contract to invoke.

  • method (str) – The name of the method to call on the contract.

  • abi (Optional[list[dict]]) – The ABI of the contract, if provided.

  • args (Optional[dict]) – The arguments to pass to the method.

  • amount (Optional[Union[Number, Decimal, str]]) – The amount to send with the invocation, if applicable.

  • asset_id (Optional[str]) – The asset ID associated with the amount, if applicable.

Returns:

The contract invocation object.

Return type:

ContractInvocation

Raises:

ValueError – If an amount is provided and an asset_id does not exist

property key: LocalAccount | None

Get the local account key.

quote_fund(amount, asset_id)

Get a quote for funding the address from your Coinbase platform account.

Parameters:
  • amount (Union[Number, Decimal, str]) – The amount to fund.

  • asset_id (str) – The ID of the Asset to fund with. For Ether, ‘eth’, ‘gwei’, and ‘wei’ are supported.

Returns:

The fund quote object.

Return type:

FundQuote

sign_payload(unsigned_payload)

Sign the given unsigned payload.

Parameters:

unsigned_payload (str) – The unsigned payload.

Returns:

The payload signature object.

Return type:

PayloadSignature

trade(amount, from_asset_id, to_asset_id)

Trade funds from the wallet address.

Parameters:
  • amount (Union[Number, Decimal, str]) – The amount to trade.

  • from_asset_id (str) – The source asset ID.

  • to_asset_id (str) – The destination asset ID.

Returns:

The created trade object.

Return type:

Trade

trades()

List trades for this wallet address.

Returns:

Iterator of trade objects.

Return type:

Iterator[Trade]

transfer(amount, asset_id, destination, gasless=False)

Transfer funds from the wallet address.

Parameters:
  • amount (Union[Number, Decimal, str]) – The amount to transfer.

  • asset_id (str) – The asset ID.

  • destination (Union[Address, 'Wallet', str]) – The transfer destination.

  • gasless (bool) – Whether to use gasless transfer.

Returns:

The created transfer object.

Return type:

Transfer

transfers()

List transfers for this wallet address.

Returns:

Iterator of transfer objects.

Return type:

Iterator[Transfer]

property wallet_id: str

Get the wallet ID.

cdp.wallet_data module

class cdp.wallet_data.WalletData(wallet_id, seed)

Bases: object

A class representing wallet data required to recreate a wallet.

classmethod from_dict(data)

Create a WalletData class instance from the given dictionary.

Parameters:

data (dict[str, str]) – The data to create the WalletData object from.

Returns:

The wallet data.

Return type:

WalletData

property seed: str

Get the seed of the wallet.

Returns:

The seed of the wallet.

Return type:

str

to_dict()

Convert the wallet data to a dictionary.

Returns:

The dictionary representation of the wallet data.

Return type:

dict[str, str]

property wallet_id: str

Get the ID of the wallet.

Returns:

The ID of the wallet.

Return type:

str

cdp.webhook module

class cdp.webhook.Webhook(model)

Bases: object

A class representing a webhook.

classmethod create(notification_uri, event_type, event_type_filter=None, event_filters=None, network_id='base-sepolia')

Create a new webhook.

Parameters:
  • notification_uri (str) – The URI where notifications should be sent.

  • event_type (WebhookEventType) – The type of event that the webhook listens to.

  • event_type_filter (WebhookEventTypeFilter) – Filter specifically for wallet or contract activity event type.

  • event_filters (List[WebhookEventTypeFilter]) – Filters applied to the events that determine which specific address(es) trigger.

  • network_id (str) – The network ID of the wallet. Defaults to “base-sepolia”.

Returns:

The created webhook object.

Return type:

Webhook

static delete(webhook_id)

Delete a webhook by its ID.

Parameters:

webhook_id (str) – The ID of the webhook to delete.

Return type:

None

property event_filters: list[WebhookEventFilter]

Get the event filters of the webhook.

Returns:

The event filters of the webhook.

Return type:

str

property event_type: WebhookEventType

Get the event type of the webhook.

Returns:

The event type of the webhook.

Return type:

str

property event_type_filter: WebhookEventTypeFilter

Get the event type filter of the webhook.

Returns:

The event type filter of the webhook.

Return type:

str

property id: str

Get the ID of the webhook.

Returns:

The ID of the webhook.

Return type:

str

classmethod list()

List webhooks.

Returns:

An iterator of webhook objects.

Return type:

Iterator[Webhook]

property network_id: str

Get the network ID of the webhook.

Returns:

The network ID of the webhook.

Return type:

str

property notification_uri: str

Get the notification URI of the webhook.

Returns:

The notification URI of the webhook.

Return type:

str

update(notification_uri=None, event_type_filter=None)

Update the webhook with a new notification URI, and/or a new list of addresses to monitor.

Parameters:
  • notification_uri (str) – The new URI for webhook notifications.

  • event_type_filter (WebhookEventTypeFilter) – The new eventTypeFilter that contains a new list (replacement) of addresses to monitor for the webhook.

Returns:

The updated webhook object.

Return type:

Webhook

Module contents

class cdp.Address(network_id, address_id)

Bases: object

A class representing an address.

property address_id: str

Get the address ID.

Returns:

The address ID.

Return type:

str

balance(asset_id)

Get the balance of the address.

Parameters:

asset_id (str) – The asset ID.

Returns:

The balance of the address.

Return type:

Decimal

balances()

List balances of the address.

Returns:

The balances of the address, keyed by asset ID. Ether balances are denominated in ETH.

Return type:

BalanceMap

property can_sign: bool

Get whether the address can sign.

Returns:

Whether the address can sign.

Return type:

bool

faucet(asset_id=None)

Request faucet funds.

Parameters:

asset_id (str) – The asset ID.

Returns:

The faucet transaction object.

Return type:

FaucetTransaction

historical_balances(asset_id)

List historical balances.

Parameters:

asset_id (str) – The asset ID.

Returns:

An iterator of HistoricalBalance objects.

Return type:

Iterator[HistoricalBalance]

Raises:

Exception – If there’s an error listing the historical balances.

property network_id: str

Get the network ID.

Returns:

The network ID.

Return type:

str

transactions()

List transactions of the address.

Returns:

An iterator of Transaction objects.

Return type:

Iterator[Transaction]

Raises:

Exception – If there’s an error listing the transactions.

class cdp.Asset(network_id, asset_id, contract_address, decimals)

Bases: object

A class representing an asset.

property asset_id: str

Get the asset ID.

Returns:

The asset ID.

Return type:

str

property contract_address: str

Get the contract address.

Returns:

The contract address.

Return type:

str

property decimals: int

Get the number of decimals for the asset.

Returns:

The number of decimals.

Return type:

int

classmethod fetch(network_id, asset_id)

Fetch an asset from the API.

Parameters:
  • network_id (str) – The network ID.

  • asset_id (str) – The asset ID.

Returns:

The fetched Asset instance.

Return type:

Asset

from_atomic_amount(atomic_amount)

Convert an atomic amount to a whole amount.

Parameters:

atomic_amount (Decimal) – The atomic amount.

Returns:

The whole amount.

Return type:

Decimal

classmethod from_model(model, asset_id=None)

Create an Asset instance from a model.

Parameters:
  • model (AssetModel) – The model representing the asset.

  • asset_id (Optional[str]) – The asset ID.

Returns:

The Asset instance.

Return type:

Asset

property network_id: str

Get the network ID.

Returns:

The network ID.

Return type:

str

static primary_denomination(asset_id)

Get the primary denomination for a given asset ID.

Parameters:

asset_id (str) – The asset ID.

Returns:

The primary denomination of the asset.

Return type:

str

to_atomic_amount(whole_amount)

Convert a whole amount to an atomic amount.

Parameters:

whole_amount (Decimal) – The whole amount.

Returns:

The atomic amount.

Return type:

Decimal

class cdp.Balance(amount, asset, asset_id=None)

Bases: object

A class representing a balance.

property amount: Decimal

Get the amount.

Returns:

The amount.

Return type:

Decimal

property asset: Asset

Get the asset.

Returns:

The asset.

Return type:

Asset

property asset_id: str

Get the asset ID.

Returns:

The asset ID.

Return type:

str

static from_model(model, asset_id=None)

Create a Balance instance from a model.

Parameters:
  • model (BalanceModel) – The model representing the balance.

  • asset_id (Optional[str]) – The asset ID.

Returns:

The Balance instance.

Return type:

Balance

class cdp.BalanceMap

Bases: dict[str, Decimal]

A class representing asset balances.

This class extends the built-in dict class, where keys are asset IDs (str) and values are balance amounts (Decimal).

add(balance)

Add a Balance object to the BalanceMap.

Parameters:

balance (Balance) – The Balance object to add.

Raises:

ValueError – If the provided balance is not a Balance instance.

Return type:

None

classmethod from_models(models)

Create a BalanceMap instance from a list of BalanceModel objects.

Parameters:

models (List[BalanceModel]) – A list of BalanceModel objects.

Returns:

A new BalanceMap instance populated with the given models.

Return type:

BalanceMap

class cdp.Cdp

Bases: object

The Cdp class is a singleton responsible for configuring and managing the Coinbase API client.

api_key_name

The API key name.

Type:

Optional[str]

private_key

The private key associated with the API key.

Type:

Optional[str]

use_server_signer

Whether to use the server signer.

Type:

bool

debugging

Whether debugging is enabled.

Type:

bool

base_path

The base URL for the Platform API.

Type:

str

max_network_retries

The maximum number of network retries.

Type:

int

api_clients

The Platform API clients instance.

Type:

Optional[ApiClients]

api_clients: ApiClients | None = None
api_key_name = None
base_path = 'https://api.cdp.coinbase.com/platform'
classmethod configure(api_key_name, private_key, use_server_signer=False, debugging=False, base_path='https://api.cdp.coinbase.com/platform', max_network_retries=3, source='sdk', source_version='0.12.1')

Configure the CDP SDK.

Parameters:
  • api_key_name (str) – The API key name.

  • private_key (str) – The private key associated with the API key.

  • use_server_signer (bool) – Whether to use the server signer. Defaults to False.

  • debugging (bool) – Whether debugging is enabled. Defaults to False.

  • base_path (str) – The base URL for the CDP API. Defaults to “https://api.cdp.coinbase.com/platform”.

  • max_network_retries (int) – The maximum number of network retries. Defaults to 3.

  • source (Optional[str]) – Specifies whether the sdk is being used directly or if it’s an Agentkit extension.

  • source_version (Optional[str]) – The version of the source package.

Return type:

None

classmethod configure_from_json(file_path='~/Downloads/cdp_api_key.json', use_server_signer=False, debugging=False, base_path='https://api.cdp.coinbase.com/platform', max_network_retries=3, source='sdk', source_version='0.12.1')

Configure the CDP SDK from a JSON file.

Parameters:
  • file_path (str) – The path to the JSON file. Defaults to “~/Downloads/cdp_api_key.json”.

  • use_server_signer (bool) – Whether to use the server signer. Defaults to False.

  • debugging (bool) – Whether debugging is enabled. Defaults to False.

  • base_path (str) – The base URL for the CDP API. Defaults to “https://api.cdp.coinbase.com/platform”.

  • max_network_retries (int) – The maximum number of network retries. Defaults to 3.

  • source (Optional[str]) – Specifies whether the sdk is being used directly or if it’s an Agentkit extension.

  • source_version (Optional[str]) – The version of the source package.

Raises:

InvalidConfigurationError – If the JSON file is missing the ‘api_key_name’ or ‘private_key’.

Return type:

None

debugging = False
max_network_retries = 3
private_key = None
use_server_signer = False
class cdp.ContractInvocation(model)

Bases: object

A class representing a contract invocation.

property abi: dict[str, Any]

Get the ABI of the contract invocation.

Returns:

The ABI JSON.

Return type:

Dict

property address_id: str

Get the address ID of the contract invocation.

Returns:

The address ID.

Return type:

str

property amount: Decimal

Get the amount sent to the contract in atomic units.

Returns:

The amount in atomic units.

Return type:

Decimal

property args: dict[str, Any]

Get the arguments passed to the contract method.

Returns:

The arguments passed to the contract method.

Return type:

Dict

broadcast()

Broadcast the contract invocation to the network.

Returns:

The broadcasted ContractInvocation object.

Return type:

ContractInvocation

Raises:

TransactionNotSignedError – If the transaction is not signed.

property contract_address: str

Get the contract address.

Returns:

The contract address.

Return type:

str

property contract_invocation_id: str

Get the contract invocation ID.

Returns:

The contract invocation ID.

Return type:

str

classmethod create(address_id, wallet_id, network_id, contract_address, method, abi=None, args=None, amount=None, asset_id=None)

Create a new ContractInvocation object.

Parameters:
  • address_id (str) – The address ID of the signing address.

  • wallet_id (str) – The wallet ID associated with the signing address.

  • network_id (str) – The Network ID.

  • contract_address (str) – The contract address.

  • method (str) – The contract method.

  • abi (Optional[list[dict]]) – The contract ABI, if provided.

  • args (Optional[dict]) – The arguments to pass to the contract method.

  • amount (Optional[Decimal]) – The amount of native asset to send to a payable contract method.

  • asset_id (Optional[str]) – The asset ID to send to the contract.

Returns:

The new ContractInvocation object.

Return type:

ContractInvocation

classmethod list(wallet_id, address_id)

List Contract Invocations.

Parameters:
  • wallet_id (str) – The wallet ID.

  • address_id (str) – The address ID.

Returns:

An iterator of ContractInvocation objects.

Return type:

Iterator[ContractInvocation]

property method: str

Get the method being invoked in the contract.

Returns:

The method being invoked.

Return type:

str

property network_id: str

Get the network ID of the contract invocation.

Returns:

The network ID.

Return type:

str

reload()

Reload the Contract Invocation model with the latest version from the server.

Returns:

The updated ContractInvocation object.

Return type:

ContractInvocation

sign(key)

Sign the contract invocation transaction with the given key.

Parameters:

key (LocalAccount) – The key to sign the contract invocation with.

Returns:

The signed ContractInvocation object.

Return type:

ContractInvocation

Raises:

ValueError – If the key is not a LocalAccount.

property status: str

Get the status of the contract invocation.

Returns:

The status.

Return type:

str

property transaction: Transaction | None

Get the transaction associated with the contract invocation.

Returns:

The transaction.

Return type:

Transaction

property transaction_hash: str

Get the transaction hash of the contract invocation.

Returns:

The transaction hash.

Return type:

str

Get the link to the transaction on the blockchain explorer.

Returns:

The transaction link.

Return type:

str

wait(interval_seconds=0.2, timeout_seconds=20)

Wait until the contract invocation is signed or fails by polling the server.

Parameters:
  • interval_seconds (float) – The interval at which to poll the server.

  • timeout_seconds (float) – The maximum time to wait before timing out.

Returns:

The completed contract invocation.

Return type:

ContractInvocation

Raises:

TimeoutError – If the invocation takes longer than the given timeout.

property wallet_id: str

Get the wallet ID of the contract invocation.

Returns:

The wallet ID.

Return type:

str

class cdp.FaucetTransaction(model)

Bases: object

A class representing a faucet transaction.

property address_id: str

Get the address.

Returns:

The address.

Return type:

str

property network_id: str

Get the network ID.

Returns:

The network ID.

Return type:

str

reload()

Reload the faucet transaction.

Return type:

FaucetTransaction

Returns:

None

property status: str

Get the faucet transaction status.

Returns:

The faucet transaction status.

Return type:

str

property transaction: Transaction

Get the Faucet transaction.

property transaction_hash: str

Get the transaction hash.

Returns:

The transaction hash.

Return type:

str

Get the transaction link.

Returns:

The transaction link.

Return type:

str

wait(interval_seconds=0.2, timeout_seconds=20)

Wait for the faucet transaction to complete.

Parameters:
  • interval_seconds (float) – The interval seconds.

  • timeout_seconds (float) – The timeout seconds.

Returns:

The faucet transaction.

Return type:

FaucetTransaction

class cdp.PayloadSignature(model)

Bases: object

A representation of a Payload Signature.

class Status(value)

Bases: Enum

Enumeration of Payload Signature statuses.

FAILED = 'failed'
PENDING = 'pending'
SIGNED = 'signed'
classmethod terminal_states()

Get the terminal states.

Returns:

The terminal states.

Return type:

List[str]

property address_id: str

Get the address ID.

Returns:

The address ID.

Return type:

str

classmethod create(wallet_id, address_id, unsigned_payload, signature=None)

Create a payload signature.

Parameters:
  • wallet_id (str) – The wallet ID.

  • address_id (str) – The address ID.

  • unsigned_payload (str) – The unsigned payload.

  • signature (Optional[str]) – The signature.

Returns:

The payload signature.

Return type:

PayloadSignature

Raises:

Exception – If there’s an error creating the payload signature..

classmethod list(wallet_id, address_id)

List payload signatures.

Parameters:
  • wallet_id (str) – The wallet ID.

  • address_id (str) – The address ID.

Returns:

An iterator of payload signatures.

Return type:

Iterator[Payload]

Raises:

Exception – If there’s an error listing the payload signatures.

property payload_signature_id: str

Get the payload signature ID.

Returns:

The payload signature ID.

Return type:

str

reload()

Reload the payload signature.

Return type:

None

property signature: str

Get the signature.

Returns:

The signature.

Return type:

str

property status: Status

Get the status.

Returns:

The status.

Return type:

PayloadSignature.Status

property terminal_state: bool

Check if the Transaction is in a terminal state.

Returns:

Whether the paylaod signature is in a terminal state.

Return type:

bool

property unsigned_payload: str

Get the unsigned payload.

Returns:

The unsigned payload.

Return type:

str

wait(interval_seconds=0.2, timeout_seconds=20)

Wait for the payload signature to complete.

Parameters:
  • interval_seconds (float) – The interval seconds.

  • timeout_seconds (float) – The timeout seconds.

Returns:

The payload signature.

Return type:

PayloadSignature

property wallet_id: str

Get the wallet ID.

Returns:

The wallet ID.

Return type:

str

class cdp.SmartContract(model)

Bases: object

A representation of a SmartContract on the blockchain.

class MultiTokenContractOptions(uri)

Bases: dict

Options for multi-token contracts (ERC1155).

class NFTContractOptions(name, symbol, base_uri)

Bases: dict

Options for NFT contracts (ERC721).

class TokenContractOptions(name, symbol, total_supply)

Bases: dict

Options for token contracts (ERC20).

class Type(value)

Bases: Enum

Enumeration of SmartContract types.

ERC1155 = 'erc1155'
ERC20 = 'erc20'
ERC721 = 'erc721'
property abi: dict[str, Any]

Get the ABI of the smart contract.

Returns:

The ABI as a JSON object.

broadcast()

Broadcast the smart contract deployment to the network.

Return type:

SmartContract

Returns:

The broadcasted SmartContract object.

Raises:

ValueError – If the smart contract deployment is not signed.

property contract_address: str

Get the contract address of the smart contract.

Returns:

The contract address.

classmethod create(wallet_id, address_id, type, options)

Create a new SmartContract object.

Parameters:
  • wallet_id (str) – The ID of the wallet that will deploy the smart contract.

  • address_id (str) – The ID of the address that will deploy the smart contract.

  • type (Type) – The type of the smart contract (ERC20, ERC721, or ERC1155).

  • options (TokenContractOptions | NFTContractOptions | MultiTokenContractOptions) – The options of the smart contract.

Return type:

SmartContract

Returns:

The created smart contract.

Raises:

ValueError – If the options type is unsupported.

property deployer_address: str

Get the deployer address of the smart contract.

Returns:

The deployer address.

property network_id: str

Get the network ID of the smart contract.

Returns:

The network ID.

property options: TokenContractOptions | NFTContractOptions | MultiTokenContractOptions

Get the options of the smart contract.

Returns:

The smart contract options as a higher-level options class.

Raises:

ValueError – If the smart contract type is unknown or if options are not set.

classmethod read(network_id, contract_address, method, abi=None, args=None)

Read data from a smart contract.

Parameters:
  • network_id (str) – The ID of the network.

  • contract_address (str) – The address of the smart contract.

  • method (str) – The method to call on the smart contract.

  • abi (Optional[list[dict]]) – The ABI of the smart contract.

  • args (Optional[dict]) – The arguments to pass to the method.

Return type:

SmartContract

Returns:

The data read from the smart contract.

reload()

Reload the SmartContract model with the latest data from the server.

Return type:

SmartContract

Returns:

The updated SmartContract object.

sign(key)

Sign the smart contract deployment with the given key.

Parameters:

key (LocalAccount) – The key to sign the smart contract deployment with.

Return type:

SmartContract

Returns:

The signed SmartContract object.

Raises:

ValueError – If the key is not a LocalAccount.

property smart_contract_id: str

Get the smart contract ID.

Returns:

The smart contract ID.

property transaction: Transaction | None

Get the transaction associated with the smart contract deployment.

Returns:

The transaction.

Return type:

Transaction

property type: Type

Get the type of the smart contract.

Returns:

The smart contract type.

Raises:

ValueError – If the smart contract type is unknown.

wait(interval_seconds=0.2, timeout_seconds=10)

Wait until the smart contract deployment is confirmed on the network or fails onchain.

Parameters:
  • interval_seconds (float) – The interval to check the status of the smart contract deployment.

  • timeout_seconds (float) – The maximum time to wait for the smart contract deployment to be confirmed.

Return type:

SmartContract

Returns:

The SmartContract object in a terminal state.

Raises:

TimeoutError – If the smart contract deployment times out.

property wallet_id: str

Get the wallet ID that deployed the smart contract.

Returns:

The wallet ID.

class cdp.SponsoredSend(model)

Bases: object

A representation of an onchain Sponsored Send.

class Status(value)

Bases: Enum

Enumeration of SponsoredSend statuses.

COMPLETE = 'complete'
FAILED = 'failed'
PENDING = 'pending'
SIGNED = 'signed'
SUBMITTED = 'submitted'
classmethod terminal_states()

Get the terminal states.

Returns:

The terminal states.

Return type:

List[str]

sign(key)

Sign the Transaction with the provided key.

Parameters:

key (LocalAccount) – The Ethereum account to sign with.

Returns:

The hex-encoded signed payload.

Return type:

str

Raises:

ValueError – If the transaction is already signed.

property signature: str | None

Get the signature of the typed data.

Returns:

The signature, if available.

Return type:

Optional[str]

property signed: bool

Check if the Transaction has been signed.

Returns:

True if signed, False otherwise.

Return type:

bool

property status: Status

Get the status of the Transaction.

Returns:

The current status.

Return type:

Status

property terminal_state: bool

Check if the Sponsored Send is in a terminal state.

Returns:

True if in a terminal state, False otherwise.

Return type:

bool

property transaction_hash: str

Get the Transaction Hash of the Transaction.

Returns:

The Transaction Hash.

Return type:

str

Get the link to the transaction on the blockchain explorer.

Returns:

The link to the transaction.

Return type:

str

property typed_data_hash: str

Get the Keccak256 hash of the typed data.

Returns:

The Keccak256 hash of the typed data.

Return type:

str

class cdp.Trade(model)

Bases: object

A class representing a trade.

property address_id: str

Get the address ID.

Returns:

The address ID.

Return type:

str

property approve_transaction: Transaction | None

Get the approve transaction.

broadcast()

Broadcast the trade.

Returns:

The broadcasted trade.

Return type:

Trade

Raises:

TransactionNotSignedError – If the trade is not signed.

static create(address_id, from_asset_id, to_asset_id, amount, network_id, wallet_id)

Create a new trade.

Parameters:
  • address_id (str) – The ID of the address to use for the trade.

  • from_asset_id (str) – The ID of the asset to trade.

  • to_asset_id (str) – The ID of the asset to receive from the trade.

  • amount (Decimal) – The amount to trade.

  • network_id (str) – The ID of the network to use for the trade.

  • wallet_id (str) – The ID of the wallet to use for the trade.

Returns:

The created trade.

Return type:

Trade

property from_amount: Decimal

Get the from amount.

Returns:

The from amount.

Return type:

Decimal

property from_asset_id: str

Get the from asset ID.

Returns:

The from asset ID.

Return type:

str

classmethod list(wallet_id, address_id)

List all trades for an address.

Parameters:
  • wallet_id (str) – The ID of the wallet to list trades for.

  • address_id (str) – The ID of the address to list trades for.

Returns:

An iterator of trade objects.

Return type:

Iterator[Trade]

property network_id: str

Get the network ID.

Returns:

The network ID.

Return type:

str

reload()

Reload the trade.

Return type:

None

property status: str

Get the status.

Returns:

The status.

Return type:

str

property to_amount: Decimal

Get the to amount.

Returns:

The to amount.

Return type:

Decimal

property to_asset_id: str

Get the to asset ID.

Returns:

The to asset ID.

Return type:

str

property trade_id: str

Get the trade ID.

Returns:

The trade ID.

Return type:

str

property transaction: Transaction

Get the trade transaction.

wait(interval_seconds=0.2, timeout_seconds=20)

Wait for the trade to complete.

Parameters:
  • interval_seconds (float) – The interval seconds.

  • timeout_seconds (float) – The timeout seconds.

Returns:

The trade.

Return type:

Trade

property wallet_id: str

Get the wallet ID.

Returns:

The wallet ID.

Return type:

str

class cdp.Transaction(model)

Bases: object

A representation of an onchain Transaction.

class Status(value)

Bases: Enum

Enumeration of Transaction statuses.

BROADCAST = 'broadcast'
COMPLETE = 'complete'
FAILED = 'failed'
PENDING = 'pending'
SIGNED = 'signed'
UNSPECIFIED = 'unspecified'
classmethod terminal_states()

Get the terminal states.

Returns:

The terminal states.

Return type:

List[str]

property block_hash: str

Get the block hash of which the Transaction is recorded.

property block_height: str

Get the block height of which the Transaction is recorded.

property content: str

Get the content of the transaction.

property from_address_id: str

Get the from address ID.

classmethod list(network_id, address_id)

List transactions of the address.

Parameters:
  • network_id (str) – The ID of the network to list transaction for.

  • address_id (str) – The ID of the address to list transaction for.

Returns:

An iterator of Transaction objects.

Return type:

Iterator[Transaction]

Raises:

Exception – If there’s an error listing the transactions.

property network_id: str

Get the Network ID of the Transaction.

property raw: DynamicFeeTransaction

Get the underlying raw transaction.

sign(key)

Sign the Transaction with the provided key.

Parameters:

key (LocalAccount) – The Ethereum account to sign with.

Returns:

The hex-encoded signed payload.

Return type:

str

Raises:

ValueError – If the transaction is already signed.

property signature: str

Get the signature of the Transaction.

property signed: bool

Check if the Transaction has been signed.

property signed_payload: str

Get the signed payload.

property status: Status

Get the status.

property terminal_state: bool

Check if the Transaction is in a terminal state.

property to_address_id: str

Get the to address ID.

property transaction_hash: str

Get the transaction hash.

Get the transaction link.

property unsigned_payload: str

Get the unsigned payload.

class cdp.Transfer(model)

Bases: object

A class representing a transfer.

property amount: Decimal

Get the amount of the asset for the Transfer.

property asset: Asset

Get the Asset of the Transfer.

property asset_id: str

Get the Asset ID of the Transfer.

broadcast()

Broadcast the Transfer to the Network.

Returns:

The Transfer object.

Return type:

Transfer

Raises:

TransactionNotSignedError – If the Transfer is not signed.

classmethod create(address_id, amount, asset_id, destination, network_id, wallet_id, gasless=False)

Create a transfer.

Parameters:
  • address_id (str) – The address ID.

  • amount (Decimal) – The amount.

  • asset_id (str) – The asset ID.

  • destination (Union[Address, Wallet, str]) – The destination.

  • network_id (str) – The network ID.

  • wallet_id (str) – The wallet ID.

  • gasless (bool) – Whether to use gasless.

Returns:

The transfer.

Return type:

Transfer

property destination_address_id: str

Get the Destination Address ID of the Transfer.

property from_address_id: str

Get the from address ID.

Returns:

The from address ID.

Return type:

str

classmethod list(wallet_id, address_id)

List transfers.

Parameters:
  • wallet_id (str) – The wallet ID.

  • address_id (str) – The address ID.

Returns:

An iterator of transfer objects.

Return type:

Iterator[Transfer]

Raises:

Exception – If there’s an error listing the transfers.

property network_id: str

Get the Network ID of the Transfer.

reload()

Reload the transfer.

Return type:

None

Returns:

None

property send_tx_delegate: SponsoredSend | Transaction | None

Get the appropriate delegate for the transfer (SponsoredSend or Transaction).

sign(key)

Sign the Transfer with the given key.

Parameters:

key (LocalAccount) – The key to sign the Transfer with.

Returns:

The Transfer object.

Return type:

Transfer

Raises:

ValueError – If the key is not a LocalAccount.

property sponsored_send: SponsoredSend | None

Get the SponsoredSend of the Transfer, if the transfer is gasless.

property status: str

Get the status.

Returns:

The status.

Return type:

str

property terminal_state: bool

Check if the Transfer is in a terminal state.

property transaction: Transaction | None

Get the Transfer transaction.

property transaction_hash: str

Get the Transaction Hash of the Transfer.

Get the link to the transaction on the blockchain explorer.

property transfer_id: str

Get the transfer ID.

Returns:

The transfer ID.

Return type:

str

wait(interval_seconds=0.2, timeout_seconds=20)

Wait for the transfer to complete.

Parameters:
  • interval_seconds (float) – The interval seconds.

  • timeout_seconds (float) – The timeout seconds.

Returns:

The transfer.

Return type:

Transfer

property wallet_id: str

Get the wallet ID.

Returns:

The wallet ID.

Return type:

str

class cdp.Wallet(model, seed=None)

Bases: object

A class representing a wallet.

MAX_ADDRESSES: int = 20

The maximum number of addresses that can be associated with a wallet.

property addresses: list[WalletAddress]

Get the addresses of the wallet.

Returns:

The addresses of the wallet.

Return type:

List[WalletAddress]

balance(asset_id)

Get the balance of a specific asset for the default address.

Parameters:

asset_id (str) – The ID of the asset to check the balance for.

Returns:

The balance of the specified asset.

Return type:

Any

Raises:

ValueError – If the default address does not exist.

balances()

List balances of the address.

Returns:

The balances of the address, keyed by asset ID. Ether balances are denominated in ETH.

Return type:

BalanceMap

Raises:

ValueError – If the default address does not exist.

property can_sign: bool

Check if the wallet can sign transactions.

Returns:

True if the wallet can sign, False otherwise.

Return type:

bool

classmethod create(network_id='base-sepolia', interval_seconds=0.2, timeout_seconds=20)

Create a new wallet.

Parameters:
  • network_id (str) – The network ID of the wallet. Defaults to “base-sepolia”.

  • interval_seconds (float) – The interval between checks in seconds. Defaults to 0.2.

  • timeout_seconds (float) – The maximum time to wait for the server signer to be active. Defaults to 20.

Returns:

The created wallet object.

Return type:

Wallet

Raises:

Exception – If there’s an error creating the wallet.

create_address()

Create a new address for the wallet.

Returns:

The created address object.

Return type:

WalletAddress

Raises:

Exception – If there’s an error creating the address.

create_webhook(notification_uri)

Create a new webhook for the wallet.

Parameters:

notification_uri (str) – The notification URI of the webhook.

Returns:

The created webhook object. It can be used to monitor activities happening in the wallet. When they occur, webhook will make a request to the specified URI.

Return type:

Webhook

Raises:

Exception – If there’s an error creating the webhook.

property default_address: WalletAddress | None

Get the default address of the wallet.

Returns:

The default address object, or None if not set.

Return type:

Optional[WalletAddress]

deploy_multi_token(uri)

Deploy a multi-token smart contract.

Parameters:

uri (str) – The URI for the multi-token contract.

Returns:

The deployed smart contract.

Return type:

SmartContract

Raises:

ValueError – If the default address does not exist.

deploy_nft(name, symbol, base_uri)

Deploy an NFT smart contract.

Parameters:
  • name (str) – The name of the NFT.

  • symbol (str) – The symbol of the NFT.

  • base_uri (str) – The base URI for the NFT.

Returns:

The deployed smart contract.

Return type:

SmartContract

Raises:

ValueError – If the default address does not exist.

deploy_token(name, symbol, total_supply)

Deploy a token smart contract.

Parameters:
  • name (str) – The name of the token.

  • symbol (str) – The symbol of the token.

  • total_supply (Union[Number, Decimal, str]) – The total supply of the token.

Returns:

The deployed smart contract.

Return type:

SmartContract

Raises:

ValueError – If the default address does not exist.

export_data()

Export the wallet’s data.

Returns:

The wallet’s data.

Return type:

WalletData

Raises:

ValueError – If the wallet does not have a seed loaded.

faucet(asset_id=None)

Request faucet funds.

Parameters:

asset_id (Optional[str]) – The asset ID. Defaults to None.

Returns:

The faucet transaction object.

Return type:

FaucetTransaction

Raises:

ValueError – If the default address does not exist.

classmethod fetch(wallet_id)

Fetch a wallet by its ID.

Parameters:

wallet_id (str) – The ID of the wallet to retrieve.

Returns:

The retrieved wallet object.

Return type:

Wallet

Raises:

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

fund(amount, asset_id)

Fund the wallet from your account on the Coinbase Platform.

Parameters:
  • amount (Union[Number, Decimal, str]) – The amount of the Asset to fund the wallet with.

  • asset_id (str) – The ID of the Asset to fund with. For Ether, ‘eth’, ‘gwei’, and ‘wei’ are supported.

Returns:

The created fund operation object.

Return type:

FundOperation

Raises:

ValueError – If the default address does not exist.

property id: str

Get the ID of the wallet.

Returns:

The ID of the wallet.

Return type:

str

classmethod import_data(data)

Import a wallet from previously exported wallet data.

Parameters:

data (WalletData) – The wallet data to import.

Returns:

The imported wallet.

Return type:

Wallet

Raises:

Exception – If there’s an error getting the wallet.

invoke_contract(contract_address, method, abi=None, args=None, amount=None, asset_id=None)

Invoke a method on the specified contract address, with the given ABI and arguments.

Parameters:
  • contract_address (str) – The address of the contract to invoke.

  • method (str) – The name of the method to call on the contract.

  • abi (Optional[list[dict]]) – The ABI of the contract, if provided.

  • args (Optional[dict]) – The arguments to pass to the method.

  • amount (Optional[Union[Number, Decimal, str]]) – The amount to send with the invocation, if applicable.

  • asset_id (Optional[str]) – The asset ID associated with the amount, if applicable.

Returns:

The contract invocation object.

Return type:

ContractInvocation

Raises:

ValueError – If the default address does not exist.

classmethod list()

List wallets.

Returns:

An iterator of wallet objects.

Return type:

Iterator[Wallet]

Raises:

Exception – If there’s an error listing the wallets.

load_seed(file_path)

Load the wallet seed from a file.

Parameters:

file_path (str) – The path to the file containing the seed data.

Raises:

ValueError – If the file does not contain seed data for this wallet or if decryption fails.

Return type:

None

property network_id: str

Get the network ID of the wallet.

Returns:

The network ID of the wallet.

Return type:

str

quote_fund(amount, asset_id)

Get a quote for funding the wallet from your Coinbase platform account.

Parameters:
  • amount (Union[Number, Decimal, str]) – The amount to fund.

  • asset_id (str) – The ID of the Asset to fund with. For Ether, ‘eth’, ‘gwei’, and ‘wei’ are supported.

Returns:

The fund quote object.

Return type:

FundQuote

Raises:

ValueError – If the default address does not exist.

reload()

Reload the wallet model from the API.

Return type:

None

Returns:

None

save_seed(file_path, encrypt=False)

Save the wallet seed to a file.

Parameters:
  • file_path (str) – The path to the file where the seed will be saved.

  • encrypt (Optional[bool]) – Whether to encrypt the seed before saving. Defaults to False.

Raises:

ValueError – If the wallet does not have a seed loaded.

Return type:

None

property server_signer_status: str

Get the server signer status of the wallet.

Returns:

The server signer status of the wallet.

Return type:

str

sign_payload(unsigned_payload)

Sign the given unsigned payload.

Parameters:

unsigned_payload (str) – The unsigned payload.

Returns:

The payload signature object.

Return type:

PayloadSignature

trade(amount, from_asset_id, to_asset_id)

Trade funds from the wallet address.

Parameters:
  • amount (Union[Number, Decimal, str]) – The amount to trade.

  • from_asset_id (str) – The asset ID to trade from.

  • to_asset_id (str) – The asset ID to trade to.

Returns:

The trade object.

Return type:

Trade

Raises:

ValueError – If the default address does not exist.

transfer(amount, asset_id, destination, gasless=False)

Transfer funds from the wallet.

Parameters:
  • amount (Union[Number, Decimal, str]) – The amount of funds to transfer.

  • asset_id (str) – The ID of the asset to transfer.

  • destination (Union[Address, 'Wallet', str]) – The destination for the transfer.

  • gasless (bool) – Whether the transfer should be gasless. Defaults to False.

Returns:

The result of the transfer operation.

Return type:

Any

Raises:

ValueError – If the default address does not exist.

class cdp.WalletAddress(model, key=None)

Bases: Address

A class representing a wallet address.

property can_sign: bool

Get whether the address can sign.

Returns:

Whether the address can sign.

Return type:

bool

deploy_multi_token(uri)

Deploy a multi-token smart contract.

Parameters:

uri (str) – The URI for the multi-token contract.

Returns:

The deployed smart contract.

Return type:

SmartContract

deploy_nft(name, symbol, base_uri)

Deploy an NFT smart contract.

Parameters:
  • name (str) – The name of the NFT.

  • symbol (str) – The symbol of the NFT.

  • base_uri (str) – The base URI for the NFT.

Returns:

The deployed smart contract.

Return type:

SmartContract

deploy_token(name, symbol, total_supply)

Deploy a token smart contract.

Parameters:
  • name (str) – The name of the token.

  • symbol (str) – The symbol of the token.

  • total_supply (Union[Number, Decimal, str]) – The total supply of the token.

Returns:

The deployed smart contract.

Return type:

SmartContract

export()

Export the wallet address’s private key as a hex string.

Returns:

The wallet address’s private key as a hex string.

Return type:

str

Raises:

ValueError – If the wallet address does not have a private key.

fund(amount, asset_id)

Fund the address from your account on the Coinbase Platform.

Parameters:
  • amount (Union[Number, Decimal, str]) – The amount of the Asset to fund the wallet with.

  • asset_id (str) – The ID of the Asset to fund with. For Ether, ‘eth’, ‘gwei’, and ‘wei’ are supported.

Returns:

The created fund operation object.

Return type:

FundOperation

invoke_contract(contract_address, method, abi=None, args=None, amount=None, asset_id=None)

Invoke a method on the specified contract address, with the given ABI and arguments.

Parameters:
  • contract_address (str) – The address of the contract to invoke.

  • method (str) – The name of the method to call on the contract.

  • abi (Optional[list[dict]]) – The ABI of the contract, if provided.

  • args (Optional[dict]) – The arguments to pass to the method.

  • amount (Optional[Union[Number, Decimal, str]]) – The amount to send with the invocation, if applicable.

  • asset_id (Optional[str]) – The asset ID associated with the amount, if applicable.

Returns:

The contract invocation object.

Return type:

ContractInvocation

Raises:

ValueError – If an amount is provided and an asset_id does not exist

property key: LocalAccount | None

Get the local account key.

quote_fund(amount, asset_id)

Get a quote for funding the address from your Coinbase platform account.

Parameters:
  • amount (Union[Number, Decimal, str]) – The amount to fund.

  • asset_id (str) – The ID of the Asset to fund with. For Ether, ‘eth’, ‘gwei’, and ‘wei’ are supported.

Returns:

The fund quote object.

Return type:

FundQuote

sign_payload(unsigned_payload)

Sign the given unsigned payload.

Parameters:

unsigned_payload (str) – The unsigned payload.

Returns:

The payload signature object.

Return type:

PayloadSignature

trade(amount, from_asset_id, to_asset_id)

Trade funds from the wallet address.

Parameters:
  • amount (Union[Number, Decimal, str]) – The amount to trade.

  • from_asset_id (str) – The source asset ID.

  • to_asset_id (str) – The destination asset ID.

Returns:

The created trade object.

Return type:

Trade

trades()

List trades for this wallet address.

Returns:

Iterator of trade objects.

Return type:

Iterator[Trade]

transfer(amount, asset_id, destination, gasless=False)

Transfer funds from the wallet address.

Parameters:
  • amount (Union[Number, Decimal, str]) – The amount to transfer.

  • asset_id (str) – The asset ID.

  • destination (Union[Address, 'Wallet', str]) – The transfer destination.

  • gasless (bool) – Whether to use gasless transfer.

Returns:

The created transfer object.

Return type:

Transfer

transfers()

List transfers for this wallet address.

Returns:

Iterator of transfer objects.

Return type:

Iterator[Transfer]

property wallet_id: str

Get the wallet ID.

class cdp.WalletData(wallet_id, seed)

Bases: object

A class representing wallet data required to recreate a wallet.

classmethod from_dict(data)

Create a WalletData class instance from the given dictionary.

Parameters:

data (dict[str, str]) – The data to create the WalletData object from.

Returns:

The wallet data.

Return type:

WalletData

property seed: str

Get the seed of the wallet.

Returns:

The seed of the wallet.

Return type:

str

to_dict()

Convert the wallet data to a dictionary.

Returns:

The dictionary representation of the wallet data.

Return type:

dict[str, str]

property wallet_id: str

Get the ID of the wallet.

Returns:

The ID of the wallet.

Return type:

str

class cdp.Webhook(model)

Bases: object

A class representing a webhook.

classmethod create(notification_uri, event_type, event_type_filter=None, event_filters=None, network_id='base-sepolia')

Create a new webhook.

Parameters:
  • notification_uri (str) – The URI where notifications should be sent.

  • event_type (WebhookEventType) – The type of event that the webhook listens to.

  • event_type_filter (WebhookEventTypeFilter) – Filter specifically for wallet or contract activity event type.

  • event_filters (List[WebhookEventTypeFilter]) – Filters applied to the events that determine which specific address(es) trigger.

  • network_id (str) – The network ID of the wallet. Defaults to “base-sepolia”.

Returns:

The created webhook object.

Return type:

Webhook

static delete(webhook_id)

Delete a webhook by its ID.

Parameters:

webhook_id (str) – The ID of the webhook to delete.

Return type:

None

property event_filters: list[WebhookEventFilter]

Get the event filters of the webhook.

Returns:

The event filters of the webhook.

Return type:

str

property event_type: WebhookEventType

Get the event type of the webhook.

Returns:

The event type of the webhook.

Return type:

str

property event_type_filter: WebhookEventTypeFilter

Get the event type filter of the webhook.

Returns:

The event type filter of the webhook.

Return type:

str

property id: str

Get the ID of the webhook.

Returns:

The ID of the webhook.

Return type:

str

classmethod list()

List webhooks.

Returns:

An iterator of webhook objects.

Return type:

Iterator[Webhook]

property network_id: str

Get the network ID of the webhook.

Returns:

The network ID of the webhook.

Return type:

str

property notification_uri: str

Get the notification URI of the webhook.

Returns:

The notification URI of the webhook.

Return type:

str

update(notification_uri=None, event_type_filter=None)

Update the webhook with a new notification URI, and/or a new list of addresses to monitor.

Parameters:
  • notification_uri (str) – The new URI for webhook notifications.

  • event_type_filter (WebhookEventTypeFilter) – The new eventTypeFilter that contains a new list (replacement) of addresses to monitor for the webhook.

Returns:

The updated webhook object.

Return type:

Webhook

cdp.hash_message(message_text)

Hashes a message according to EIP-191 and returns the hash as a 0x-prefixed hexadecimal string.

This function prefixes the message with the standard Ethereum message prefix and hashes it using Keccak-256.

Parameters:

message_text (str) – The message to hash.

Returns:

The 0x-prefixed hexadecimal string of the message hash.

Return type:

str

cdp.hash_typed_data_message(typed_data)

Hashes typed data according to EIP-712 and returns the hash as a 0x-prefixed hexadecimal string.

This function encodes the typed data as per EIP-712 and hashes it using Keccak-256.

Parameters:

typed_data (dict) – The typed data to hash, following the EIP-712 specification.

Returns:

The 0x-prefixed hexadecimal string of the typed data hash.

Return type:

str