Skip to content

Commit 550e459

Browse files
chore: Update README to Clarify Wallet Hydration + Doc Links (#45)
* chore: Update README to Clarify Wallet Hydration + Doc Links * typo
1 parent 7660b83 commit 550e459

1 file changed

Lines changed: 69 additions & 10 deletions

File tree

README.md

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ To start a Python REPL:
4242
python
4343
```
4444

45-
## Creating a Wallet
45+
## Quickstart
46+
47+
### Creating a Wallet
4648

4749
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:
4850

@@ -69,7 +71,7 @@ print("CDP SDK has been successfully configured from JSON file.")
6971

7072
This will allow you to authenticate with the Platform APIs.
7173

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
7375

7476
```python
7577
Cdp.use_server_signer = True
@@ -91,7 +93,7 @@ Wallets come with a single default address, accessible via `default_address`:
9193
address = wallet1.default_address
9294
```
9395

94-
## Funding a Wallet
96+
### Funding a Wallet
9597

9698
Wallets do not have funds on them to start. For Base Sepolia testnet, we provide a `faucet` method to fund your wallet with
9799
testnet ETH. You are allowed one faucet claim per 24-hour window.
@@ -106,7 +108,7 @@ faucet_tx.wait()
106108
print(f"Faucet transaction successfully completed: {faucet_tx}")
107109
```
108110

109-
## Transferring Funds
111+
### Transferring Funds
110112

111113
See [Transfers](https://docs.cdp.coinbase.com/wallets/docs/transfers) for more information.
112114

@@ -125,7 +127,7 @@ transfer = wallet1.transfer(0.00001, "eth", wallet2).wait()
125127
print(f"Transfer successfully completed: {transfer}")
126128
```
127129

128-
### Gasless USDC Transfers
130+
#### Gasless USDC Transfers
129131

130132
To transfer USDC without needing to hold ETH for gas, you can use the `transfer` method with the `gasless` option set to `True`.
131133

@@ -146,14 +148,14 @@ print(f"Faucet transaction successfully completed: {usdc_faucet_tx}")
146148
transfer = wallet1.transfer(0.00001, "usdc", wallet3, gasless=True).wait()
147149
```
148150

149-
## Listing Transfers
151+
### Listing Transfers
150152

151153
```python
152154
# Return list of all transfers. This will paginate and fetch all transfers for the address.
153155
list(address.transfers())
154156
```
155157

156-
## Trading Funds
158+
### Trading Funds
157159

158160
See [Trades](https://docs.cdp.coinbase.com/wallets/docs/trades) for more information.
159161

@@ -168,14 +170,68 @@ trade = wallet.trade(0.00001, "eth", "usdc").wait()
168170
print(f"Trade successfully completed: {trade}")
169171
```
170172

171-
## Listing Trades
173+
### Listing Trades
172174

173175
```python
174176
# Return list of all trades. This will paginate and fetch all trades for the address.
175177
list(address.trades())
176178
```
177179

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,
216+
# keyed by the wallet ID.
217+
fetched_data = fetch(wallet.id)
218+
219+
# imported_wallet will be equivalent to wallet.
220+
imported_wallet = Wallet.import_data(fetched_data)
221+
```
222+
223+
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
179235
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.
180236
```python
181237
from cdp.client.models.webhook import WebhookEventType
@@ -189,7 +245,7 @@ wh1 = Webhook.create(
189245
print(wh1)
190246
```
191247

192-
## Creating a Webhook On A Wallet
248+
### Creating a Webhook On A Wallet
193249
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).
194250
```python
195251
import cdp
@@ -199,6 +255,9 @@ wh1 = wallet1.create_webhook("https://your-app.com/callback")
199255
print(wh1)
200256
```
201257

258+
## Examples
259+
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).
260+
202261
## Contributing
203262

204263
See [CONTRIBUTING.md](CONTRIBUTING.md) for more information.

0 commit comments

Comments
 (0)