cdp package¶
Subpackages¶
- cdp.client package
- Subpackages
- cdp.client.api package
- Submodules
- cdp.client.api.addresses_api module
- cdp.client.api.assets_api module
- cdp.client.api.balance_history_api module
- cdp.client.api.contract_events_api module
- cdp.client.api.contract_invocations_api module
- cdp.client.api.external_addresses_api module
- cdp.client.api.fund_api module
- cdp.client.api.mpc_wallet_stake_api module
- cdp.client.api.networks_api module
- cdp.client.api.onchain_identity_api module
- cdp.client.api.reputation_api module
- cdp.client.api.server_signers_api module
- cdp.client.api.smart_contracts_api module
- cdp.client.api.stake_api module
- cdp.client.api.trades_api module
- cdp.client.api.transaction_history_api module
- cdp.client.api.transfers_api module
- cdp.client.api.users_api module
- cdp.client.api.validators_api module
- cdp.client.api.wallet_stake_api module
- cdp.client.api.wallets_api module
- cdp.client.api.webhooks_api module
- Module contents
- cdp.client.models package
- Submodules
- cdp.client.models.abi module
- cdp.client.models.address module
- cdp.client.models.address_balance_list module
- cdp.client.models.address_historical_balance_list module
- cdp.client.models.address_list module
- cdp.client.models.address_reputation module
- cdp.client.models.address_reputation_metadata module
- cdp.client.models.address_risk module
- cdp.client.models.address_transaction_list module
- cdp.client.models.asset module
- cdp.client.models.balance module
- cdp.client.models.broadcast_contract_invocation_request module
- cdp.client.models.broadcast_staking_operation_request module
- cdp.client.models.broadcast_trade_request module
- cdp.client.models.broadcast_transfer_request module
- cdp.client.models.build_staking_operation_request module
- cdp.client.models.contract_event module
- cdp.client.models.contract_event_list module
- cdp.client.models.contract_invocation module
- cdp.client.models.contract_invocation_list module
- cdp.client.models.create_address_request module
- cdp.client.models.create_contract_invocation_request module
- cdp.client.models.create_fund_operation_request module
- cdp.client.models.create_fund_quote_request module
- cdp.client.models.create_payload_signature_request module
- cdp.client.models.create_server_signer_request module
- cdp.client.models.create_smart_contract_request module
- cdp.client.models.create_staking_operation_request module
- cdp.client.models.create_trade_request module
- cdp.client.models.create_transfer_request module
- cdp.client.models.create_wallet_request module
- cdp.client.models.create_wallet_request_wallet module
- cdp.client.models.create_wallet_webhook_request module
- cdp.client.models.create_webhook_request module
- cdp.client.models.crypto_amount module
- cdp.client.models.deploy_smart_contract_request module
- cdp.client.models.erc20_transfer_event module
- cdp.client.models.erc721_transfer_event module
- cdp.client.models.error module
- cdp.client.models.ethereum_token_transfer module
- cdp.client.models.ethereum_transaction module
- cdp.client.models.ethereum_transaction_access module
- cdp.client.models.ethereum_transaction_access_list module
- cdp.client.models.ethereum_transaction_flattened_trace module
- cdp.client.models.ethereum_validator_metadata module
- cdp.client.models.faucet_transaction module
- cdp.client.models.feature_set module
- cdp.client.models.fetch_historical_staking_balances200_response module
- cdp.client.models.fetch_staking_rewards200_response module
- cdp.client.models.fetch_staking_rewards_request module
- cdp.client.models.fiat_amount module
- cdp.client.models.fund_operation module
- cdp.client.models.fund_operation_fees module
- cdp.client.models.fund_operation_list module
- cdp.client.models.fund_quote module
- cdp.client.models.get_staking_context_request module
- cdp.client.models.historical_balance module
- cdp.client.models.multi_token_contract_options module
- cdp.client.models.network module
- cdp.client.models.network_identifier module
- cdp.client.models.nft_contract_options module
- cdp.client.models.onchain_name module
- cdp.client.models.onchain_name_list module
- cdp.client.models.onchain_name_text_records_inner module
- cdp.client.models.payload_signature module
- cdp.client.models.payload_signature_list module
- cdp.client.models.read_contract_request module
- cdp.client.models.read_smart_contract_request module
- cdp.client.models.seed_creation_event module
- cdp.client.models.seed_creation_event_result module
- cdp.client.models.server_signer module
- cdp.client.models.server_signer_event module
- cdp.client.models.server_signer_event_event module
- cdp.client.models.server_signer_event_list module
- cdp.client.models.server_signer_list module
- cdp.client.models.signature_creation_event module
- cdp.client.models.signature_creation_event_result module
- cdp.client.models.signed_voluntary_exit_message_metadata module
- cdp.client.models.smart_contract module
- cdp.client.models.smart_contract_activity_event module
- cdp.client.models.smart_contract_list module
- cdp.client.models.smart_contract_options module
- cdp.client.models.smart_contract_type module
- cdp.client.models.solidity_value module
- cdp.client.models.sponsored_send module
- cdp.client.models.staking_balance module
- cdp.client.models.staking_context module
- cdp.client.models.staking_context_context module
- cdp.client.models.staking_operation module
- cdp.client.models.staking_operation_metadata module
- cdp.client.models.staking_reward module
- cdp.client.models.staking_reward_format module
- cdp.client.models.staking_reward_usd_value module
- cdp.client.models.token_contract_options module
- cdp.client.models.token_transfer_type module
- cdp.client.models.trade module
- cdp.client.models.trade_list module
- cdp.client.models.transaction module
- cdp.client.models.transaction_content module
- cdp.client.models.transaction_type module
- cdp.client.models.transfer module
- cdp.client.models.transfer_list module
- cdp.client.models.update_webhook_request module
- cdp.client.models.user module
- cdp.client.models.validator module
- cdp.client.models.validator_details module
- cdp.client.models.validator_list module
- cdp.client.models.validator_status module
- cdp.client.models.wallet module
- cdp.client.models.wallet_list module
- cdp.client.models.webhook module
- cdp.client.models.webhook_event_filter module
- cdp.client.models.webhook_event_type module
- cdp.client.models.webhook_event_type_filter module
- cdp.client.models.webhook_list module
- cdp.client.models.webhook_smart_contract_event_filter module
- cdp.client.models.webhook_wallet_activity_filter module
- Module contents
- cdp.client.api package
- Submodules
- cdp.client.api_client module
ApiClient
ApiClient.NATIVE_TYPES_MAPPING
ApiClient.PRIMITIVE_TYPES
ApiClient.call_api()
ApiClient.deserialize()
ApiClient.files_parameters()
ApiClient.get_default()
ApiClient.param_serialize()
ApiClient.parameters_to_tuples()
ApiClient.parameters_to_url_query()
ApiClient.response_deserialize()
ApiClient.sanitize_for_serialization()
ApiClient.select_header_accept()
ApiClient.select_header_content_type()
ApiClient.set_default()
ApiClient.set_default_header()
ApiClient.update_params_for_auth()
ApiClient.user_agent
- cdp.client.api_response module
- cdp.client.configuration module
Configuration
Configuration.access_token
Configuration.assert_hostname
Configuration.auth_settings()
Configuration.cert_file
Configuration.connection_pool_maxsize
Configuration.date_format
Configuration.datetime_format
Configuration.debug
Configuration.get_api_key_with_prefix()
Configuration.get_basic_auth_token()
Configuration.get_default()
Configuration.get_default_copy()
Configuration.get_host_from_settings()
Configuration.get_host_settings()
Configuration.host
Configuration.ignore_operation_servers
Configuration.key_file
Configuration.logger
Configuration.logger_file
Configuration.logger_file_handler
Configuration.logger_format
Configuration.logger_stream_handler
Configuration.password
Configuration.proxy
Configuration.proxy_headers
Configuration.refresh_api_key_hook
Configuration.retries
Configuration.safe_chars_for_path_param
Configuration.server_operation_index
Configuration.server_operation_variables
Configuration.set_default()
Configuration.socket_options
Configuration.ssl_ca_cert
Configuration.temp_folder_path
Configuration.tls_server_name
Configuration.to_debug_report()
Configuration.username
Configuration.verify_ssl
- cdp.client.exceptions module
- cdp.client.rest module
- Module contents
- 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:
- 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:
- 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:
- _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]
- _contract_invocations¶
The ContractInvocationsApi client instance.
- Type:
Optional[ContractInvocationsApi]
- property addresses: AddressesApi¶
Get the AddressesApi client instance.
- Returns:
The AddressesApi client instance.
- Return type:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
- 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:
- 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¶
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:
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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- property transaction_hash: str¶
Get the transaction hash of the contract invocation.
- Returns:
The transaction hash.
- Return type:
str
- property transaction_link: 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:
- 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_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:
- 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:
- 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:
- 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.
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:
- 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
- property transaction_link: 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:
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:
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'¶
- property address_id: str¶
Get the Address ID.
- property amount: CryptoAmount¶
Get the crypto amount.
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- execute()¶
Execute the fund quote to create a fund operation.
- Returns:
The created fund operation.
- Return type:
- 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:
- 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 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:
- 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:
- 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 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:
- 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:
- 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:
- 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:
- Returns:
The data read from the smart contract.
- reload()¶
Reload the SmartContract model with the latest data from the server.
- Return type:
- 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:
- 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:
- 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:
- 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:
- 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
- property transaction_link: 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:
- 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:
- 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:
- 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 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.
- property transaction_link: str¶
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_id: str¶
Get the Asset ID of the Transfer.
- broadcast()¶
Broadcast the Transfer to the Network.
- Returns:
The Transfer object.
- Return type:
- 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:
- Returns:
The transfer.
- Return type:
- 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:
- 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.
- property transaction_link: str¶
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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- Raises:
ValueError – If the default address does not exist.
- export_data()¶
Export the wallet’s data.
- Returns:
The wallet’s data.
- Return type:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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.
-
MAX_ADDRESSES:
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:
- 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:
- 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:
- 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:
- 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:
- 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:
- sign_payload(unsigned_payload)¶
Sign the given unsigned payload.
- Parameters:
unsigned_payload (str) – The unsigned payload.
- Returns:
The payload signature object.
- Return type:
- 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:
- 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.
- 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:
- 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:
- 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:
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:
- 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:
- 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:
- 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:
- 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_id: str¶
Get the asset ID.
- Returns:
The asset ID.
- Return type:
str
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- property transaction_hash: str¶
Get the transaction hash of the contract invocation.
- Returns:
The transaction hash.
- Return type:
str
- property transaction_link: 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:
- 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:
- 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
- property transaction_link: 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:
- 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:
- 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 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:
- 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:
- 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:
- 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:
- Returns:
The data read from the smart contract.
- reload()¶
Reload the SmartContract model with the latest data from the server.
- Return type:
- 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:
- 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:
- 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:
- 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:
- 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
- property transaction_link: 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:
- 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:
- 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:
- 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 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.
- property transaction_link: str¶
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_id: str¶
Get the Asset ID of the Transfer.
- broadcast()¶
Broadcast the Transfer to the Network.
- Returns:
The Transfer object.
- Return type:
- 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:
- Returns:
The transfer.
- Return type:
- 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:
- 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.
- property transaction_link: str¶
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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- Raises:
ValueError – If the default address does not exist.
- export_data()¶
Export the wallet’s data.
- Returns:
The wallet’s data.
- Return type:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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.
-
MAX_ADDRESSES:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- sign_payload(unsigned_payload)¶
Sign the given unsigned payload.
- Parameters:
unsigned_payload (str) – The unsigned payload.
- Returns:
The payload signature object.
- Return type:
- 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:
- 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.
- 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:
- 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:
- 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:
- 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