You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+69-10Lines changed: 69 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,7 +42,9 @@ To start a Python REPL:
42
42
python
43
43
```
44
44
45
-
## Creating a Wallet
45
+
## Quickstart
46
+
47
+
### Creating a Wallet
46
48
47
49
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:
48
50
@@ -69,7 +71,7 @@ print("CDP SDK has been successfully configured from JSON file.")
69
71
70
72
This will allow you to authenticate with the Platform APIs.
71
73
72
-
If you are using a CDP Server-Signer to manage your private keys, enable it with
74
+
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
73
75
74
76
```python
75
77
Cdp.use_server_signer =True
@@ -91,7 +93,7 @@ Wallets come with a single default address, accessible via `default_address`:
91
93
address = wallet1.default_address
92
94
```
93
95
94
-
## Funding a Wallet
96
+
###Funding a Wallet
95
97
96
98
Wallets do not have funds on them to start. For Base Sepolia testnet, we provide a `faucet` method to fund your wallet with
97
99
testnet ETH. You are allowed one faucet claim per 24-hour window.
# Return list of all trades. This will paginate and fetch all trades for the address.
175
177
list(address.trades())
176
178
```
177
179
178
-
## Creating a Webhook
180
+
### Re-Instantiating Wallets
181
+
182
+
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.
183
+
184
+
```python
185
+
# Export the data required to re-instantiate the wallet. The data contains the seed and the ID of the wallet.
186
+
data = wallet.export_data()
187
+
```
188
+
189
+
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.
190
+
191
+
```python
192
+
# You should implement the "store" method to securely persist the data object,
193
+
# which is required to re-instantiate the wallet at a later time. For ease of use,
194
+
# the data object is converted to a dictionary first.
195
+
store(data.to_dict())
196
+
```
197
+
198
+
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.
199
+
200
+
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`.
201
+
202
+
```python
203
+
# Pick a file to which to save your wallet seed.
204
+
file_path ="my_seed.json"
205
+
206
+
# Set encrypt=True to encrypt the wallet seed with your CDP secret API key.
207
+
wallet.save_seed(file_path, encrypt=True)
208
+
209
+
print(f"Seed for wallet {wallet.id} successfully saved to {file_path}.")
210
+
```
211
+
212
+
The below code demonstrates how to re-instantiate a wallet from the data export.
213
+
214
+
```python
215
+
# You should implement the "fetch" method to retrieve the securely persisted data object,
To import Wallets that were persisted to your local file system using `save_seed`, use the below code.
224
+
225
+
```python
226
+
# Get the unhydrated wallet from the server.
227
+
fetched_wallet = Wallet.fetch(wallet.id)
228
+
229
+
# You can now load the seed into the wallet from the local file.
230
+
# fetched_wallet will be equivalent to imported_wallet.
231
+
fetched_wallet.load_seed(file_path)
232
+
```
233
+
234
+
### Creating a Webhook
179
235
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.
180
236
```python
181
237
from cdp.client.models.webhook import WebhookEventType
@@ -189,7 +245,7 @@ wh1 = Webhook.create(
189
245
print(wh1)
190
246
```
191
247
192
-
## Creating a Webhook On A Wallet
248
+
###Creating a Webhook On A Wallet
193
249
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).
0 commit comments