cdp-sdk 0.12.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. cdp_sdk-0.12.0/LICENSE.md +15 -0
  2. cdp_sdk-0.12.0/PKG-INFO +296 -0
  3. cdp_sdk-0.12.0/README.md +271 -0
  4. cdp_sdk-0.12.0/cdp/__init__.py +42 -0
  5. cdp_sdk-0.12.0/cdp/__version__.py +1 -0
  6. cdp_sdk-0.12.0/cdp/address.py +142 -0
  7. cdp_sdk-0.12.0/cdp/api_clients.py +252 -0
  8. cdp_sdk-0.12.0/cdp/asset.py +165 -0
  9. cdp_sdk-0.12.0/cdp/balance.py +79 -0
  10. cdp_sdk-0.12.0/cdp/balance_map.py +75 -0
  11. cdp_sdk-0.12.0/cdp/cdp.py +136 -0
  12. cdp_sdk-0.12.0/cdp/cdp_api_client.py +247 -0
  13. cdp_sdk-0.12.0/cdp/client/__init__.py +167 -0
  14. cdp_sdk-0.12.0/cdp/client/api/__init__.py +24 -0
  15. cdp_sdk-0.12.0/cdp/client/api/addresses_api.py +2683 -0
  16. cdp_sdk-0.12.0/cdp/client/api/assets_api.py +313 -0
  17. cdp_sdk-0.12.0/cdp/client/api/balance_history_api.py +363 -0
  18. cdp_sdk-0.12.0/cdp/client/api/contract_events_api.py +416 -0
  19. cdp_sdk-0.12.0/cdp/client/api/contract_invocations_api.py +1262 -0
  20. cdp_sdk-0.12.0/cdp/client/api/external_addresses_api.py +1222 -0
  21. cdp_sdk-0.12.0/cdp/client/api/fund_api.py +1248 -0
  22. cdp_sdk-0.12.0/cdp/client/api/mpc_wallet_stake_api.py +951 -0
  23. cdp_sdk-0.12.0/cdp/client/api/networks_api.py +298 -0
  24. cdp_sdk-0.12.0/cdp/client/api/onchain_identity_api.py +366 -0
  25. cdp_sdk-0.12.0/cdp/client/api/reputation_api.py +589 -0
  26. cdp_sdk-0.12.0/cdp/client/api/server_signers_api.py +1729 -0
  27. cdp_sdk-0.12.0/cdp/client/api/smart_contracts_api.py +1824 -0
  28. cdp_sdk-0.12.0/cdp/client/api/stake_api.py +2186 -0
  29. cdp_sdk-0.12.0/cdp/client/api/trades_api.py +1262 -0
  30. cdp_sdk-0.12.0/cdp/client/api/transaction_history_api.py +348 -0
  31. cdp_sdk-0.12.0/cdp/client/api/transfers_api.py +1262 -0
  32. cdp_sdk-0.12.0/cdp/client/api/users_api.py +281 -0
  33. cdp_sdk-0.12.0/cdp/client/api/validators_api.py +653 -0
  34. cdp_sdk-0.12.0/cdp/client/api/wallet_stake_api.py +945 -0
  35. cdp_sdk-0.12.0/cdp/client/api/wallets_api.py +1390 -0
  36. cdp_sdk-0.12.0/cdp/client/api/webhooks_api.py +1431 -0
  37. cdp_sdk-0.12.0/cdp/client/api_client.py +797 -0
  38. cdp_sdk-0.12.0/cdp/client/api_response.py +21 -0
  39. cdp_sdk-0.12.0/cdp/client/configuration.py +450 -0
  40. cdp_sdk-0.12.0/cdp/client/exceptions.py +199 -0
  41. cdp_sdk-0.12.0/cdp/client/models/__init__.py +131 -0
  42. cdp_sdk-0.12.0/cdp/client/models/abi.py +89 -0
  43. cdp_sdk-0.12.0/cdp/client/models/address.py +95 -0
  44. cdp_sdk-0.12.0/cdp/client/models/address_balance_list.py +101 -0
  45. cdp_sdk-0.12.0/cdp/client/models/address_historical_balance_list.py +99 -0
  46. cdp_sdk-0.12.0/cdp/client/models/address_list.py +101 -0
  47. cdp_sdk-0.12.0/cdp/client/models/address_reputation.py +93 -0
  48. cdp_sdk-0.12.0/cdp/client/models/address_reputation_metadata.py +105 -0
  49. cdp_sdk-0.12.0/cdp/client/models/address_risk.py +87 -0
  50. cdp_sdk-0.12.0/cdp/client/models/address_transaction_list.py +99 -0
  51. cdp_sdk-0.12.0/cdp/client/models/asset.py +93 -0
  52. cdp_sdk-0.12.0/cdp/client/models/balance.py +93 -0
  53. cdp_sdk-0.12.0/cdp/client/models/broadcast_contract_invocation_request.py +87 -0
  54. cdp_sdk-0.12.0/cdp/client/models/broadcast_staking_operation_request.py +89 -0
  55. cdp_sdk-0.12.0/cdp/client/models/broadcast_trade_request.py +89 -0
  56. cdp_sdk-0.12.0/cdp/client/models/broadcast_transfer_request.py +87 -0
  57. cdp_sdk-0.12.0/cdp/client/models/build_staking_operation_request.py +95 -0
  58. cdp_sdk-0.12.0/cdp/client/models/contract_event.py +112 -0
  59. cdp_sdk-0.12.0/cdp/client/models/contract_event_list.py +99 -0
  60. cdp_sdk-0.12.0/cdp/client/models/contract_invocation.py +109 -0
  61. cdp_sdk-0.12.0/cdp/client/models/contract_invocation_list.py +101 -0
  62. cdp_sdk-0.12.0/cdp/client/models/create_address_request.py +91 -0
  63. cdp_sdk-0.12.0/cdp/client/models/create_contract_invocation_request.py +95 -0
  64. cdp_sdk-0.12.0/cdp/client/models/create_fund_operation_request.py +91 -0
  65. cdp_sdk-0.12.0/cdp/client/models/create_fund_quote_request.py +89 -0
  66. cdp_sdk-0.12.0/cdp/client/models/create_payload_signature_request.py +89 -0
  67. cdp_sdk-0.12.0/cdp/client/models/create_server_signer_request.py +91 -0
  68. cdp_sdk-0.12.0/cdp/client/models/create_smart_contract_request.py +94 -0
  69. cdp_sdk-0.12.0/cdp/client/models/create_staking_operation_request.py +93 -0
  70. cdp_sdk-0.12.0/cdp/client/models/create_trade_request.py +91 -0
  71. cdp_sdk-0.12.0/cdp/client/models/create_transfer_request.py +95 -0
  72. cdp_sdk-0.12.0/cdp/client/models/create_wallet_request.py +91 -0
  73. cdp_sdk-0.12.0/cdp/client/models/create_wallet_request_wallet.py +89 -0
  74. cdp_sdk-0.12.0/cdp/client/models/create_wallet_webhook_request.py +89 -0
  75. cdp_sdk-0.12.0/cdp/client/models/create_webhook_request.py +110 -0
  76. cdp_sdk-0.12.0/cdp/client/models/crypto_amount.py +93 -0
  77. cdp_sdk-0.12.0/cdp/client/models/deploy_smart_contract_request.py +87 -0
  78. cdp_sdk-0.12.0/cdp/client/models/erc20_transfer_event.py +112 -0
  79. cdp_sdk-0.12.0/cdp/client/models/erc721_transfer_event.py +112 -0
  80. cdp_sdk-0.12.0/cdp/client/models/error.py +92 -0
  81. cdp_sdk-0.12.0/cdp/client/models/ethereum_token_transfer.py +100 -0
  82. cdp_sdk-0.12.0/cdp/client/models/ethereum_transaction.py +144 -0
  83. cdp_sdk-0.12.0/cdp/client/models/ethereum_transaction_access.py +89 -0
  84. cdp_sdk-0.12.0/cdp/client/models/ethereum_transaction_access_list.py +95 -0
  85. cdp_sdk-0.12.0/cdp/client/models/ethereum_transaction_flattened_trace.py +123 -0
  86. cdp_sdk-0.12.0/cdp/client/models/ethereum_validator_metadata.py +110 -0
  87. cdp_sdk-0.12.0/cdp/client/models/faucet_transaction.py +95 -0
  88. cdp_sdk-0.12.0/cdp/client/models/feature_set.py +97 -0
  89. cdp_sdk-0.12.0/cdp/client/models/fetch_historical_staking_balances200_response.py +99 -0
  90. cdp_sdk-0.12.0/cdp/client/models/fetch_staking_rewards200_response.py +99 -0
  91. cdp_sdk-0.12.0/cdp/client/models/fetch_staking_rewards_request.py +99 -0
  92. cdp_sdk-0.12.0/cdp/client/models/fiat_amount.py +89 -0
  93. cdp_sdk-0.12.0/cdp/client/models/fund_operation.py +120 -0
  94. cdp_sdk-0.12.0/cdp/client/models/fund_operation_fees.py +97 -0
  95. cdp_sdk-0.12.0/cdp/client/models/fund_operation_list.py +101 -0
  96. cdp_sdk-0.12.0/cdp/client/models/fund_quote.py +114 -0
  97. cdp_sdk-0.12.0/cdp/client/models/get_staking_context_request.py +93 -0
  98. cdp_sdk-0.12.0/cdp/client/models/historical_balance.py +97 -0
  99. cdp_sdk-0.12.0/cdp/client/models/multi_token_contract_options.py +87 -0
  100. cdp_sdk-0.12.0/cdp/client/models/network.py +117 -0
  101. cdp_sdk-0.12.0/cdp/client/models/network_identifier.py +43 -0
  102. cdp_sdk-0.12.0/cdp/client/models/nft_contract_options.py +91 -0
  103. cdp_sdk-0.12.0/cdp/client/models/onchain_name.py +106 -0
  104. cdp_sdk-0.12.0/cdp/client/models/onchain_name_list.py +101 -0
  105. cdp_sdk-0.12.0/cdp/client/models/onchain_name_text_records_inner.py +89 -0
  106. cdp_sdk-0.12.0/cdp/client/models/payload_signature.py +104 -0
  107. cdp_sdk-0.12.0/cdp/client/models/payload_signature_list.py +101 -0
  108. cdp_sdk-0.12.0/cdp/client/models/read_contract_request.py +91 -0
  109. cdp_sdk-0.12.0/cdp/client/models/read_smart_contract_request.py +91 -0
  110. cdp_sdk-0.12.0/cdp/client/models/seed_creation_event.py +89 -0
  111. cdp_sdk-0.12.0/cdp/client/models/seed_creation_event_result.py +93 -0
  112. cdp_sdk-0.12.0/cdp/client/models/server_signer.py +91 -0
  113. cdp_sdk-0.12.0/cdp/client/models/server_signer_event.py +93 -0
  114. cdp_sdk-0.12.0/cdp/client/models/server_signer_event_event.py +137 -0
  115. cdp_sdk-0.12.0/cdp/client/models/server_signer_event_list.py +101 -0
  116. cdp_sdk-0.12.0/cdp/client/models/server_signer_list.py +101 -0
  117. cdp_sdk-0.12.0/cdp/client/models/signature_creation_event.py +102 -0
  118. cdp_sdk-0.12.0/cdp/client/models/signature_creation_event_result.py +98 -0
  119. cdp_sdk-0.12.0/cdp/client/models/signed_voluntary_exit_message_metadata.py +91 -0
  120. cdp_sdk-0.12.0/cdp/client/models/smart_contract.py +114 -0
  121. cdp_sdk-0.12.0/cdp/client/models/smart_contract_activity_event.py +122 -0
  122. cdp_sdk-0.12.0/cdp/client/models/smart_contract_list.py +99 -0
  123. cdp_sdk-0.12.0/cdp/client/models/smart_contract_options.py +151 -0
  124. cdp_sdk-0.12.0/cdp/client/models/smart_contract_type.py +39 -0
  125. cdp_sdk-0.12.0/cdp/client/models/solidity_value.py +109 -0
  126. cdp_sdk-0.12.0/cdp/client/models/sponsored_send.py +106 -0
  127. cdp_sdk-0.12.0/cdp/client/models/staking_balance.py +103 -0
  128. cdp_sdk-0.12.0/cdp/client/models/staking_context.py +91 -0
  129. cdp_sdk-0.12.0/cdp/client/models/staking_context_context.py +101 -0
  130. cdp_sdk-0.12.0/cdp/client/models/staking_operation.py +118 -0
  131. cdp_sdk-0.12.0/cdp/client/models/staking_operation_metadata.py +127 -0
  132. cdp_sdk-0.12.0/cdp/client/models/staking_reward.py +110 -0
  133. cdp_sdk-0.12.0/cdp/client/models/staking_reward_format.py +37 -0
  134. cdp_sdk-0.12.0/cdp/client/models/staking_reward_usd_value.py +92 -0
  135. cdp_sdk-0.12.0/cdp/client/models/token_contract_options.py +91 -0
  136. cdp_sdk-0.12.0/cdp/client/models/token_transfer_type.py +39 -0
  137. cdp_sdk-0.12.0/cdp/client/models/trade.py +119 -0
  138. cdp_sdk-0.12.0/cdp/client/models/trade_list.py +101 -0
  139. cdp_sdk-0.12.0/cdp/client/models/transaction.py +118 -0
  140. cdp_sdk-0.12.0/cdp/client/models/transaction_content.py +123 -0
  141. cdp_sdk-0.12.0/cdp/client/models/transaction_type.py +36 -0
  142. cdp_sdk-0.12.0/cdp/client/models/transfer.py +137 -0
  143. cdp_sdk-0.12.0/cdp/client/models/transfer_list.py +101 -0
  144. cdp_sdk-0.12.0/cdp/client/models/update_webhook_request.py +103 -0
  145. cdp_sdk-0.12.0/cdp/client/models/user.py +89 -0
  146. cdp_sdk-0.12.0/cdp/client/models/validator.py +100 -0
  147. cdp_sdk-0.12.0/cdp/client/models/validator_details.py +123 -0
  148. cdp_sdk-0.12.0/cdp/client/models/validator_list.py +99 -0
  149. cdp_sdk-0.12.0/cdp/client/models/validator_status.py +48 -0
  150. cdp_sdk-0.12.0/cdp/client/models/wallet.py +113 -0
  151. cdp_sdk-0.12.0/cdp/client/models/wallet_list.py +101 -0
  152. cdp_sdk-0.12.0/cdp/client/models/webhook.py +117 -0
  153. cdp_sdk-0.12.0/cdp/client/models/webhook_event_filter.py +91 -0
  154. cdp_sdk-0.12.0/cdp/client/models/webhook_event_type.py +40 -0
  155. cdp_sdk-0.12.0/cdp/client/models/webhook_event_type_filter.py +137 -0
  156. cdp_sdk-0.12.0/cdp/client/models/webhook_list.py +99 -0
  157. cdp_sdk-0.12.0/cdp/client/models/webhook_smart_contract_event_filter.py +87 -0
  158. cdp_sdk-0.12.0/cdp/client/models/webhook_wallet_activity_filter.py +89 -0
  159. cdp_sdk-0.12.0/cdp/client/py.typed +0 -0
  160. cdp_sdk-0.12.0/cdp/client/rest.py +257 -0
  161. cdp_sdk-0.12.0/cdp/constants.py +4 -0
  162. cdp_sdk-0.12.0/cdp/contract_invocation.py +350 -0
  163. cdp_sdk-0.12.0/cdp/crypto_amount.py +116 -0
  164. cdp_sdk-0.12.0/cdp/errors.py +376 -0
  165. cdp_sdk-0.12.0/cdp/faucet_transaction.py +133 -0
  166. cdp_sdk-0.12.0/cdp/fiat_amount.py +69 -0
  167. cdp_sdk-0.12.0/cdp/fund_operation.py +247 -0
  168. cdp_sdk-0.12.0/cdp/fund_quote.py +199 -0
  169. cdp_sdk-0.12.0/cdp/hash_utils.py +40 -0
  170. cdp_sdk-0.12.0/cdp/historical_balance.py +131 -0
  171. cdp_sdk-0.12.0/cdp/payload_signature.py +228 -0
  172. cdp_sdk-0.12.0/cdp/py.typed +0 -0
  173. cdp_sdk-0.12.0/cdp/smart_contract.py +439 -0
  174. cdp_sdk-0.12.0/cdp/sponsored_send.py +164 -0
  175. cdp_sdk-0.12.0/cdp/trade.py +276 -0
  176. cdp_sdk-0.12.0/cdp/transaction.py +227 -0
  177. cdp_sdk-0.12.0/cdp/transfer.py +325 -0
  178. cdp_sdk-0.12.0/cdp/wallet.py +843 -0
  179. cdp_sdk-0.12.0/cdp/wallet_address.py +414 -0
  180. cdp_sdk-0.12.0/cdp/wallet_data.py +73 -0
  181. cdp_sdk-0.12.0/cdp/webhook.py +207 -0
  182. cdp_sdk-0.12.0/pyproject.toml +69 -0
@@ -0,0 +1,15 @@
1
+ Apache-2.0 License
2
+
3
+ Copyright 2024 Coinbase
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
@@ -0,0 +1,296 @@
1
+ Metadata-Version: 2.1
2
+ Name: cdp-sdk
3
+ Version: 0.12.0
4
+ Summary: CDP Python SDK
5
+ License: LICENSE.md
6
+ Author: John Peterson
7
+ Author-email: john.peterson@coinbase.com
8
+ Requires-Python: >=3.10,<4.0
9
+ Classifier: License :: Other/Proprietary License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Requires-Dist: bip-utils (>=2.9.3,<3.0.0)
16
+ Requires-Dist: coincurve (>=20.0.0,<21.0.0)
17
+ Requires-Dist: cryptography (>=44.0.0,<45.0.0)
18
+ Requires-Dist: pydantic (>=2.10.3,<3.0.0)
19
+ Requires-Dist: pyjwt (>=2.10.1,<3.0.0)
20
+ Requires-Dist: python-dateutil (>=2.9.0.post0,<3.0.0)
21
+ Requires-Dist: urllib3 (>=2.2.3,<3.0.0)
22
+ Requires-Dist: web3 (>=7.6.0,<8.0.0)
23
+ Description-Content-Type: text/markdown
24
+
25
+ # CDP Python SDK
26
+
27
+ The CDP Python SDK enables the simple integration of crypto into your app.
28
+ By calling Coinbase's CDP APIs, the SDK allows you to provision crypto wallets,
29
+ send crypto into/out of those wallets, track wallet balances, and trade crypto from
30
+ one asset into another.
31
+
32
+ **CDP SDK v0 is a pre-alpha release, which means that the APIs and SDK methods are subject to change. We will continuously release updates to support new capabilities and improve the developer experience.**
33
+
34
+ ## Documentation
35
+
36
+ - [CDP API Documentation](https://docs.cdp.coinbase.com/platform-apis/docs/welcome)
37
+ - [CDP SDK Python Documentation](https://coinbase.github.io/cdp-sdk-python/)
38
+
39
+ ## Requirements
40
+
41
+ - Python 3.10+
42
+ - Poetry for package management and tooling
43
+ - [Poetry Installation Instructions](https://python-poetry.org/docs/#installation)
44
+
45
+ ### Checking Python Version
46
+
47
+ Before using the SDK, ensure that you have the correct version of Python installed. The SDK requires Python 3.10 or higher. You can check your Python version by running the following code:
48
+
49
+ ```bash
50
+ python --version
51
+ pip --version
52
+ ```
53
+
54
+ If you need to upgrade your Python version, you can download and install the latest version of Python from the [official Python website](https://www.python.org/downloads/).
55
+ For `pip`, refer to the [official pip documentation](https://pip.pypa.io/en/stable/installation/) for installation instructions.
56
+
57
+ ## Installation
58
+
59
+ ```bash
60
+ pip install cdp-sdk
61
+ ```
62
+
63
+ if you prefer to manage dependencies with Poetry:
64
+ ```bash
65
+ poetry add cdp-sdk
66
+ ```
67
+
68
+ ### Starting a Python REPL
69
+
70
+ To start a Python REPL:
71
+
72
+ ```bash
73
+ python
74
+ ```
75
+
76
+ ## Quickstart
77
+
78
+ ### Creating a Wallet
79
+
80
+ To start, [create a CDP API key](https://portal.cdp.coinbase.com/access/api). Then, initialize the CDP SDK by passing your API key name and API key's private key via the `configure` method:
81
+
82
+ ```python
83
+ from cdp import *
84
+
85
+ api_key_name = "Copy your API key name here."
86
+
87
+ api_key_private_key = "Copy your API key's private key here."
88
+
89
+ Cdp.configure(api_key_name, api_key_private_key)
90
+
91
+ print("CDP SDK has been successfully configured with CDP API key.")
92
+ ```
93
+
94
+ Another way to initialize the SDK is by sourcing the API key from the JSON file that contains your API key,
95
+ downloaded from the CDP portal.
96
+
97
+ ```python
98
+ Cdp.configure_from_json("~/Downloads/cdp_api_key.json")
99
+
100
+ print("CDP SDK has been successfully configured from JSON file.")
101
+ ```
102
+
103
+ This will allow you to authenticate with the Platform APIs.
104
+
105
+ If you are using a CDP [Server-Signer](https://docs.cdp.coinbase.com/mpc-wallet/docs/serversigners) to manage your private keys, enable it with
106
+
107
+ ```python
108
+ Cdp.use_server_signer = True
109
+ ```
110
+
111
+ Now create a wallet. Wallets are created with a single default address.
112
+
113
+ ```python
114
+ # Create a wallet with one address by default.
115
+ wallet1 = Wallet.create()
116
+
117
+ print(f"Wallet successfully created: {wallet1}")
118
+ ```
119
+
120
+ Wallets come with a single default address, accessible via `default_address`:
121
+
122
+ ```python
123
+ # A wallet has a default address.
124
+ address = wallet1.default_address
125
+ ```
126
+
127
+ ### Funding a Wallet
128
+
129
+ Wallets do not have funds on them to start. For Base Sepolia testnet, we provide a `faucet` method to fund your wallet with
130
+ testnet ETH. You are allowed one faucet claim per 24-hour window.
131
+
132
+ ```python
133
+ # Fund the wallet with a faucet transaction.
134
+ faucet_tx = wallet1.faucet()
135
+
136
+ # Wait for the faucet transaction to complete.
137
+ faucet_tx.wait()
138
+
139
+ print(f"Faucet transaction successfully completed: {faucet_tx}")
140
+ ```
141
+
142
+ ### Transferring Funds
143
+
144
+ See [Transfers](https://docs.cdp.coinbase.com/wallets/docs/transfers) for more information.
145
+
146
+ Now that your faucet transaction has successfully completed, you can send the funds in your wallet to another wallet.
147
+ The code below creates another wallet, and uses the `transfer` function to send testnet ETH from the first wallet to
148
+ the second:
149
+
150
+ ```python
151
+ # Create a new wallet wallet2 to transfer funds to.
152
+ wallet2 = Wallet.create()
153
+
154
+ print(f"Wallet successfully created: {wallet2}")
155
+
156
+ transfer = wallet1.transfer(0.00001, "eth", wallet2).wait()
157
+
158
+ print(f"Transfer successfully completed: {transfer}")
159
+ ```
160
+
161
+ #### Gasless USDC Transfers
162
+
163
+ To transfer USDC without needing to hold ETH for gas, you can use the `transfer` method with the `gasless` option set to `True`.
164
+
165
+ ```python
166
+ # Create a new wallet wallet3 to transfer funds to.
167
+ wallet3 = Wallet.create()
168
+
169
+ print(f"Wallet successfully created: {wallet3}")
170
+
171
+ # Fund the wallet with USDC with a faucet transaction.
172
+ usdc_faucet_tx = wallet1.faucet("usdc")
173
+
174
+ # Wait for the faucet transaction to complete.
175
+ usdc_faucet_tx.wait()
176
+
177
+ print(f"Faucet transaction successfully completed: {usdc_faucet_tx}")
178
+
179
+ transfer = wallet1.transfer(0.00001, "usdc", wallet3, gasless=True).wait()
180
+ ```
181
+
182
+ ### Listing Transfers
183
+
184
+ ```python
185
+ # Return list of all transfers. This will paginate and fetch all transfers for the address.
186
+ list(address.transfers())
187
+ ```
188
+
189
+ ### Trading Funds
190
+
191
+ See [Trades](https://docs.cdp.coinbase.com/wallets/docs/trades) for more information.
192
+
193
+ ```python
194
+ wallet = Wallet.create("base-mainnet")
195
+
196
+ print(f"Wallet successfully created: {wallet}")
197
+ print(f"Send `base-mainnet` ETH to wallets default address: {wallet.default_address.address_id}")
198
+
199
+ trade = wallet.trade(0.00001, "eth", "usdc").wait()
200
+
201
+ print(f"Trade successfully completed: {trade}")
202
+ ```
203
+
204
+ ### Listing Trades
205
+
206
+ ```python
207
+ # Return list of all trades. This will paginate and fetch all trades for the address.
208
+ list(address.trades())
209
+ ```
210
+
211
+ ### Re-Instantiating Wallets
212
+
213
+ The SDK creates wallets with [Developer-Managed (1-1)](https://docs.cdp.coinbase.com/mpc-wallet/docs/wallets#developer-managed-wallets) keys by default, which means you are responsible for securely storing the keys required to re-instantiate wallets. The below code walks you through how to export a wallet and store it in a secure location.
214
+
215
+ ```python
216
+ # Export the data required to re-instantiate the wallet. The data contains the seed and the ID of the wallet.
217
+ data = wallet.export_data()
218
+ ```
219
+
220
+ In order to persist the data for the wallet, you will need to implement a store method to store the data export in a secure location. If you do not store the wallet in a secure location you will lose access to the wallet and all of the funds on it.
221
+
222
+ ```python
223
+ # You should implement the "store" method to securely persist the data object,
224
+ # which is required to re-instantiate the wallet at a later time. For ease of use,
225
+ # the data object is converted to a dictionary first.
226
+ store(data.to_dict())
227
+ ```
228
+
229
+ For convenience during testing, we provide a `save_seed` method that stores the wallet's seed in your local file system. This is an insecure method of storing wallet seeds and should only be used for development purposes.
230
+
231
+ To encrypt the saved data, set encrypt to `True`. Note that your CDP API key also serves as the encryption key for the data persisted locally. To re-instantiate wallets with encrypted data, ensure that your SDK is configured with the same API key when invoking `save_seed` and `load_seed`.
232
+
233
+ ```python
234
+ # Pick a file to which to save your wallet seed.
235
+ file_path = "my_seed.json"
236
+
237
+ # Set encrypt=True to encrypt the wallet seed with your CDP secret API key.
238
+ wallet.save_seed(file_path, encrypt=True)
239
+
240
+ print(f"Seed for wallet {wallet.id} successfully saved to {file_path}.")
241
+ ```
242
+
243
+ The below code demonstrates how to re-instantiate a wallet from the data export.
244
+
245
+ ```python
246
+ # You should implement the "fetch" method to retrieve the securely persisted data object,
247
+ # keyed by the wallet ID.
248
+ fetched_data = fetch(wallet.id)
249
+
250
+ # imported_wallet will be equivalent to wallet.
251
+ imported_wallet = Wallet.import_data(fetched_data)
252
+ ```
253
+
254
+ To import Wallets that were persisted to your local file system using `save_seed`, use the below code.
255
+
256
+ ```python
257
+ # Get the unhydrated wallet from the server.
258
+ fetched_wallet = Wallet.fetch(wallet.id)
259
+
260
+ # You can now load the seed into the wallet from the local file.
261
+ # fetched_wallet will be equivalent to imported_wallet.
262
+ fetched_wallet.load_seed(file_path)
263
+ ```
264
+
265
+ ### Creating a Webhook
266
+ A webhook is a way to provide other applications with real-time information from the blockchain. When an event occurs on a blockchain address, it can send a POST request to a URL you specify. You can create a webhook to receive notifications about events that occur in your wallet or crypto address, such as when a user makes a transfer.
267
+ ```python
268
+ from cdp.client.models.webhook import WebhookEventType
269
+ from cdp.client.models.webhook import WebhookEventFilter
270
+
271
+ wh1 = Webhook.create(
272
+ notification_uri="https://your-app.com/callback",
273
+ event_type=WebhookEventType.ERC20_TRANSFER,
274
+ event_filters=[WebhookEventFilter(from_address="0x71d4d7d5e9ce0f41e6a68bd3a9b43aa597dc0eb0")]
275
+ )
276
+ print(wh1)
277
+ ```
278
+
279
+ ### Creating a Webhook On A Wallet
280
+ A webhook can be attached to an existing wallet to monitor events that occur on the wallet, i.e. all addresses associated with this wallet. A list of supported blockchain events can be found [here](https://docs.cdp.coinbase.com/get-started/docs/webhooks/event-types).
281
+ ```python
282
+ import cdp
283
+
284
+ wallet1 = Wallet.create()
285
+ wh1 = wallet1.create_webhook("https://your-app.com/callback")
286
+ print(wh1)
287
+ ```
288
+
289
+ ## Examples
290
+ Examples, demo apps, and further code samples can be found in the [CDP SDK Python Documentation](https://docs.cdp.coinbase.com/cdp-apis/docs/welcome).
291
+
292
+ ## Contributing
293
+
294
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for more information.
295
+
296
+
@@ -0,0 +1,271 @@
1
+ # CDP Python SDK
2
+
3
+ The CDP Python SDK enables the simple integration of crypto into your app.
4
+ By calling Coinbase's CDP APIs, the SDK allows you to provision crypto wallets,
5
+ send crypto into/out of those wallets, track wallet balances, and trade crypto from
6
+ one asset into another.
7
+
8
+ **CDP SDK v0 is a pre-alpha release, which means that the APIs and SDK methods are subject to change. We will continuously release updates to support new capabilities and improve the developer experience.**
9
+
10
+ ## Documentation
11
+
12
+ - [CDP API Documentation](https://docs.cdp.coinbase.com/platform-apis/docs/welcome)
13
+ - [CDP SDK Python Documentation](https://coinbase.github.io/cdp-sdk-python/)
14
+
15
+ ## Requirements
16
+
17
+ - Python 3.10+
18
+ - Poetry for package management and tooling
19
+ - [Poetry Installation Instructions](https://python-poetry.org/docs/#installation)
20
+
21
+ ### Checking Python Version
22
+
23
+ Before using the SDK, ensure that you have the correct version of Python installed. The SDK requires Python 3.10 or higher. You can check your Python version by running the following code:
24
+
25
+ ```bash
26
+ python --version
27
+ pip --version
28
+ ```
29
+
30
+ If you need to upgrade your Python version, you can download and install the latest version of Python from the [official Python website](https://www.python.org/downloads/).
31
+ For `pip`, refer to the [official pip documentation](https://pip.pypa.io/en/stable/installation/) for installation instructions.
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ pip install cdp-sdk
37
+ ```
38
+
39
+ if you prefer to manage dependencies with Poetry:
40
+ ```bash
41
+ poetry add cdp-sdk
42
+ ```
43
+
44
+ ### Starting a Python REPL
45
+
46
+ To start a Python REPL:
47
+
48
+ ```bash
49
+ python
50
+ ```
51
+
52
+ ## Quickstart
53
+
54
+ ### Creating a Wallet
55
+
56
+ To start, [create a CDP API key](https://portal.cdp.coinbase.com/access/api). Then, initialize the CDP SDK by passing your API key name and API key's private key via the `configure` method:
57
+
58
+ ```python
59
+ from cdp import *
60
+
61
+ api_key_name = "Copy your API key name here."
62
+
63
+ api_key_private_key = "Copy your API key's private key here."
64
+
65
+ Cdp.configure(api_key_name, api_key_private_key)
66
+
67
+ print("CDP SDK has been successfully configured with CDP API key.")
68
+ ```
69
+
70
+ Another way to initialize the SDK is by sourcing the API key from the JSON file that contains your API key,
71
+ downloaded from the CDP portal.
72
+
73
+ ```python
74
+ Cdp.configure_from_json("~/Downloads/cdp_api_key.json")
75
+
76
+ print("CDP SDK has been successfully configured from JSON file.")
77
+ ```
78
+
79
+ This will allow you to authenticate with the Platform APIs.
80
+
81
+ If you are using a CDP [Server-Signer](https://docs.cdp.coinbase.com/mpc-wallet/docs/serversigners) to manage your private keys, enable it with
82
+
83
+ ```python
84
+ Cdp.use_server_signer = True
85
+ ```
86
+
87
+ Now create a wallet. Wallets are created with a single default address.
88
+
89
+ ```python
90
+ # Create a wallet with one address by default.
91
+ wallet1 = Wallet.create()
92
+
93
+ print(f"Wallet successfully created: {wallet1}")
94
+ ```
95
+
96
+ Wallets come with a single default address, accessible via `default_address`:
97
+
98
+ ```python
99
+ # A wallet has a default address.
100
+ address = wallet1.default_address
101
+ ```
102
+
103
+ ### Funding a Wallet
104
+
105
+ Wallets do not have funds on them to start. For Base Sepolia testnet, we provide a `faucet` method to fund your wallet with
106
+ testnet ETH. You are allowed one faucet claim per 24-hour window.
107
+
108
+ ```python
109
+ # Fund the wallet with a faucet transaction.
110
+ faucet_tx = wallet1.faucet()
111
+
112
+ # Wait for the faucet transaction to complete.
113
+ faucet_tx.wait()
114
+
115
+ print(f"Faucet transaction successfully completed: {faucet_tx}")
116
+ ```
117
+
118
+ ### Transferring Funds
119
+
120
+ See [Transfers](https://docs.cdp.coinbase.com/wallets/docs/transfers) for more information.
121
+
122
+ Now that your faucet transaction has successfully completed, you can send the funds in your wallet to another wallet.
123
+ The code below creates another wallet, and uses the `transfer` function to send testnet ETH from the first wallet to
124
+ the second:
125
+
126
+ ```python
127
+ # Create a new wallet wallet2 to transfer funds to.
128
+ wallet2 = Wallet.create()
129
+
130
+ print(f"Wallet successfully created: {wallet2}")
131
+
132
+ transfer = wallet1.transfer(0.00001, "eth", wallet2).wait()
133
+
134
+ print(f"Transfer successfully completed: {transfer}")
135
+ ```
136
+
137
+ #### Gasless USDC Transfers
138
+
139
+ To transfer USDC without needing to hold ETH for gas, you can use the `transfer` method with the `gasless` option set to `True`.
140
+
141
+ ```python
142
+ # Create a new wallet wallet3 to transfer funds to.
143
+ wallet3 = Wallet.create()
144
+
145
+ print(f"Wallet successfully created: {wallet3}")
146
+
147
+ # Fund the wallet with USDC with a faucet transaction.
148
+ usdc_faucet_tx = wallet1.faucet("usdc")
149
+
150
+ # Wait for the faucet transaction to complete.
151
+ usdc_faucet_tx.wait()
152
+
153
+ print(f"Faucet transaction successfully completed: {usdc_faucet_tx}")
154
+
155
+ transfer = wallet1.transfer(0.00001, "usdc", wallet3, gasless=True).wait()
156
+ ```
157
+
158
+ ### Listing Transfers
159
+
160
+ ```python
161
+ # Return list of all transfers. This will paginate and fetch all transfers for the address.
162
+ list(address.transfers())
163
+ ```
164
+
165
+ ### Trading Funds
166
+
167
+ See [Trades](https://docs.cdp.coinbase.com/wallets/docs/trades) for more information.
168
+
169
+ ```python
170
+ wallet = Wallet.create("base-mainnet")
171
+
172
+ print(f"Wallet successfully created: {wallet}")
173
+ print(f"Send `base-mainnet` ETH to wallets default address: {wallet.default_address.address_id}")
174
+
175
+ trade = wallet.trade(0.00001, "eth", "usdc").wait()
176
+
177
+ print(f"Trade successfully completed: {trade}")
178
+ ```
179
+
180
+ ### Listing Trades
181
+
182
+ ```python
183
+ # Return list of all trades. This will paginate and fetch all trades for the address.
184
+ list(address.trades())
185
+ ```
186
+
187
+ ### Re-Instantiating Wallets
188
+
189
+ The SDK creates wallets with [Developer-Managed (1-1)](https://docs.cdp.coinbase.com/mpc-wallet/docs/wallets#developer-managed-wallets) keys by default, which means you are responsible for securely storing the keys required to re-instantiate wallets. The below code walks you through how to export a wallet and store it in a secure location.
190
+
191
+ ```python
192
+ # Export the data required to re-instantiate the wallet. The data contains the seed and the ID of the wallet.
193
+ data = wallet.export_data()
194
+ ```
195
+
196
+ In order to persist the data for the wallet, you will need to implement a store method to store the data export in a secure location. If you do not store the wallet in a secure location you will lose access to the wallet and all of the funds on it.
197
+
198
+ ```python
199
+ # You should implement the "store" method to securely persist the data object,
200
+ # which is required to re-instantiate the wallet at a later time. For ease of use,
201
+ # the data object is converted to a dictionary first.
202
+ store(data.to_dict())
203
+ ```
204
+
205
+ For convenience during testing, we provide a `save_seed` method that stores the wallet's seed in your local file system. This is an insecure method of storing wallet seeds and should only be used for development purposes.
206
+
207
+ To encrypt the saved data, set encrypt to `True`. Note that your CDP API key also serves as the encryption key for the data persisted locally. To re-instantiate wallets with encrypted data, ensure that your SDK is configured with the same API key when invoking `save_seed` and `load_seed`.
208
+
209
+ ```python
210
+ # Pick a file to which to save your wallet seed.
211
+ file_path = "my_seed.json"
212
+
213
+ # Set encrypt=True to encrypt the wallet seed with your CDP secret API key.
214
+ wallet.save_seed(file_path, encrypt=True)
215
+
216
+ print(f"Seed for wallet {wallet.id} successfully saved to {file_path}.")
217
+ ```
218
+
219
+ The below code demonstrates how to re-instantiate a wallet from the data export.
220
+
221
+ ```python
222
+ # You should implement the "fetch" method to retrieve the securely persisted data object,
223
+ # keyed by the wallet ID.
224
+ fetched_data = fetch(wallet.id)
225
+
226
+ # imported_wallet will be equivalent to wallet.
227
+ imported_wallet = Wallet.import_data(fetched_data)
228
+ ```
229
+
230
+ To import Wallets that were persisted to your local file system using `save_seed`, use the below code.
231
+
232
+ ```python
233
+ # Get the unhydrated wallet from the server.
234
+ fetched_wallet = Wallet.fetch(wallet.id)
235
+
236
+ # You can now load the seed into the wallet from the local file.
237
+ # fetched_wallet will be equivalent to imported_wallet.
238
+ fetched_wallet.load_seed(file_path)
239
+ ```
240
+
241
+ ### Creating a Webhook
242
+ A webhook is a way to provide other applications with real-time information from the blockchain. When an event occurs on a blockchain address, it can send a POST request to a URL you specify. You can create a webhook to receive notifications about events that occur in your wallet or crypto address, such as when a user makes a transfer.
243
+ ```python
244
+ from cdp.client.models.webhook import WebhookEventType
245
+ from cdp.client.models.webhook import WebhookEventFilter
246
+
247
+ wh1 = Webhook.create(
248
+ notification_uri="https://your-app.com/callback",
249
+ event_type=WebhookEventType.ERC20_TRANSFER,
250
+ event_filters=[WebhookEventFilter(from_address="0x71d4d7d5e9ce0f41e6a68bd3a9b43aa597dc0eb0")]
251
+ )
252
+ print(wh1)
253
+ ```
254
+
255
+ ### Creating a Webhook On A Wallet
256
+ A webhook can be attached to an existing wallet to monitor events that occur on the wallet, i.e. all addresses associated with this wallet. A list of supported blockchain events can be found [here](https://docs.cdp.coinbase.com/get-started/docs/webhooks/event-types).
257
+ ```python
258
+ import cdp
259
+
260
+ wallet1 = Wallet.create()
261
+ wh1 = wallet1.create_webhook("https://your-app.com/callback")
262
+ print(wh1)
263
+ ```
264
+
265
+ ## Examples
266
+ Examples, demo apps, and further code samples can be found in the [CDP SDK Python Documentation](https://docs.cdp.coinbase.com/cdp-apis/docs/welcome).
267
+
268
+ ## Contributing
269
+
270
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for more information.
271
+
@@ -0,0 +1,42 @@
1
+ from cdp.__version__ import __version__
2
+ from cdp.address import Address
3
+ from cdp.asset import Asset
4
+ from cdp.balance import Balance
5
+ from cdp.balance_map import BalanceMap
6
+ from cdp.cdp import Cdp
7
+ from cdp.contract_invocation import ContractInvocation
8
+ from cdp.faucet_transaction import FaucetTransaction
9
+ from cdp.hash_utils import hash_message, hash_typed_data_message
10
+ from cdp.payload_signature import PayloadSignature
11
+ from cdp.smart_contract import SmartContract
12
+ from cdp.sponsored_send import SponsoredSend
13
+ from cdp.trade import Trade
14
+ from cdp.transaction import Transaction
15
+ from cdp.transfer import Transfer
16
+ from cdp.wallet import Wallet
17
+ from cdp.wallet_address import WalletAddress
18
+ from cdp.wallet_data import WalletData
19
+ from cdp.webhook import Webhook
20
+
21
+ __all__ = [
22
+ "__version__",
23
+ "Cdp",
24
+ "ContractInvocation",
25
+ "Wallet",
26
+ "WalletAddress",
27
+ "WalletData",
28
+ "Webhook",
29
+ "Asset",
30
+ "Transfer",
31
+ "Address",
32
+ "Transaction",
33
+ "Balance",
34
+ "BalanceMap",
35
+ "FaucetTransaction",
36
+ "Trade",
37
+ "SponsoredSend",
38
+ "PayloadSignature",
39
+ "SmartContract",
40
+ "hash_message",
41
+ "hash_typed_data_message",
42
+ ]
@@ -0,0 +1 @@
1
+ __version__ = "0.12.0"