cdp-docs-cli 1.0.0
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.
- package/README.md +213 -0
- package/bin/cdp-docs.js +48 -0
- package/bin/cdp-setup.js +91 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +212 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -0
- package/src/templates/docs/exporting.md +0 -0
- package/src/templates/docs/fund.md +122 -0
- package/src/templates/docs/importing.md +273 -0
- package/src/templates/docs/managing-accounts.md +366 -0
- package/src/templates/docs/policies.md +730 -0
- package/src/templates/docs/transfer.md +366 -0
- package/src/templates/docs/wallet-accounts.md +203 -0
- package/src/templates/docs/wallet-start.md +741 -0
- package/src/templates/prompt/INTEGRATION-SUMMARY.md +151 -0
- package/src/templates/prompt/SETUP-CDP-WALLET.md +142 -0
- package/src/templates/prompt/cdp-wallet.md +1155 -0
- package/src/templates/prompt/context.md +105 -0
- package/src/templates/prompt/directory.md +97 -0
@@ -0,0 +1,366 @@
|
|
1
|
+
# Managing Accounts
|
2
|
+
|
3
|
+
## Creating Accounts
|
4
|
+
|
5
|
+
You can assign a name to an account to make it easier to access. Account names can consist of alphanumeric characters and hyphens, and must be between 2 and 36 characters long. Account names must be unique within a single CDP project for each account type (e.g., all Solana accounts).
|
6
|
+
|
7
|
+
You can assign an account name at the time of account creation, and retrieve it later using the name. The `getOrCreateAccount` method will create an account if it doesn't exist, and return the existing account if it does.
|
8
|
+
|
9
|
+
### EVM Accounts
|
10
|
+
|
11
|
+
You can create EVM accounts with or without names. Here are examples of both approaches:
|
12
|
+
|
13
|
+
<CodeGroup>
|
14
|
+
```ts TypeScript lines wrap
|
15
|
+
import { CdpClient } from "@coinbase/cdp-sdk";
|
16
|
+
import "dotenv/config";
|
17
|
+
|
18
|
+
const cdp = new CdpClient();
|
19
|
+
|
20
|
+
const account = await cdp.evm.createAccount();
|
21
|
+
console.log(`Created account. Address: ${account.address}.`);
|
22
|
+
|
23
|
+
const namedAccount = await cdp.evm.getOrCreateAccount({
|
24
|
+
name: "MyAccount"
|
25
|
+
});
|
26
|
+
console.log(`Created account with name ${account.name}.`);
|
27
|
+
```
|
28
|
+
|
29
|
+
```python Python lines wrap
|
30
|
+
import asyncio
|
31
|
+
from cdp import CdpClient
|
32
|
+
import dotenv
|
33
|
+
|
34
|
+
dotenv.load_dotenv()
|
35
|
+
|
36
|
+
async def main():
|
37
|
+
async with CdpClient() as cdp:
|
38
|
+
account = await cdp.evm.create_account()
|
39
|
+
print(f"Created account. Address: {account.address}.")
|
40
|
+
|
41
|
+
named_account = await cdp.evm.get_or_create_account(name="MyAccount")
|
42
|
+
print(f"Created account with name {named_account.name}.")
|
43
|
+
|
44
|
+
asyncio.run(main())
|
45
|
+
```
|
46
|
+
</CodeGroup>
|
47
|
+
|
48
|
+
### Smart Accounts
|
49
|
+
|
50
|
+
You can also create and manage smart accounts that are owned by an EVM account. Each owner account can only have one smart account associated with it. The `getOrCreateSmartAccount` method will create a smart account if it doesn't exist for the owner, and return the existing smart account if it does.
|
51
|
+
|
52
|
+
<CodeGroup>
|
53
|
+
```ts TypeScript lines wrap
|
54
|
+
import { CdpClient } from "@coinbase/cdp-sdk";
|
55
|
+
import "dotenv/config";
|
56
|
+
|
57
|
+
const cdp = new CdpClient();
|
58
|
+
|
59
|
+
// Create a couple of owners, one for each smart account we will create.
|
60
|
+
const firstOwner = await cdp.evm.getOrCreateAccount({
|
61
|
+
name: "ExampleOwner1"
|
62
|
+
});
|
63
|
+
const secondOwner = await cdp.evm.getOrCreateAccount({
|
64
|
+
name: "ExampleOwner2"
|
65
|
+
});
|
66
|
+
|
67
|
+
const account = await cdp.evm.createSmartAccount({
|
68
|
+
owner: firstOwner,
|
69
|
+
});
|
70
|
+
console.log("Created Smart Account. Address:", account.address);
|
71
|
+
|
72
|
+
const namedSmartAccount = await cdp.evm.getOrCreateSmartAccount({
|
73
|
+
name: "MySmartAccount",
|
74
|
+
owner: secondOwner
|
75
|
+
});
|
76
|
+
console.log("Created Smart Account:", sameAccount.address);
|
77
|
+
```
|
78
|
+
|
79
|
+
```python Python lines wrap
|
80
|
+
import asyncio
|
81
|
+
from cdp import CdpClient
|
82
|
+
import dotenv
|
83
|
+
|
84
|
+
dotenv.load_dotenv()
|
85
|
+
|
86
|
+
async def main():
|
87
|
+
async with CdpClient() as cdp:
|
88
|
+
# Create a couple of owners, one for each smart account we will create.
|
89
|
+
first_owner = await cdp.evm.get_or_create_account(name="ExampleOwner1")
|
90
|
+
second_owner = await cdp.evm.get_or_create_account(name="ExampleOwner2")
|
91
|
+
|
92
|
+
account = await cdp.evm.create_smart_account(
|
93
|
+
owner=first_owner
|
94
|
+
)
|
95
|
+
print("Created Smart Account. Address:", account.address)
|
96
|
+
|
97
|
+
named_account = await cdp.evm.get_or_create_smart_account(
|
98
|
+
name="MySmartAccount",
|
99
|
+
owner=second_owner
|
100
|
+
)
|
101
|
+
print("Created Smart Account:", named_account.address)
|
102
|
+
|
103
|
+
asyncio.run(main())
|
104
|
+
```
|
105
|
+
</CodeGroup>
|
106
|
+
|
107
|
+
### Solana Accounts
|
108
|
+
|
109
|
+
You can create Solana accounts with or without names. Here are examples of both approaches:
|
110
|
+
|
111
|
+
<CodeGroup>
|
112
|
+
```ts TypeScript lines wrap
|
113
|
+
import { CdpClient } from "@coinbase/cdp-sdk";
|
114
|
+
import "dotenv/config";
|
115
|
+
|
116
|
+
const cdp = new CdpClient();
|
117
|
+
|
118
|
+
const account = await cdp.solana.createAccount();
|
119
|
+
console.log(`Created account. Address: ${account.address}.`);
|
120
|
+
|
121
|
+
const namedAccount = await cdp.solana.getOrCreateAccount({
|
122
|
+
name: "MyAccount"
|
123
|
+
});
|
124
|
+
console.log(`Created account with name ${namedAccount.name}.`);
|
125
|
+
```
|
126
|
+
|
127
|
+
```python Python lines wrap
|
128
|
+
import asyncio
|
129
|
+
from cdp import CdpClient
|
130
|
+
import dotenv
|
131
|
+
|
132
|
+
dotenv.load_dotenv()
|
133
|
+
|
134
|
+
async def main():
|
135
|
+
async with CdpClient() as cdp:
|
136
|
+
account = await cdp.solana.create_account()
|
137
|
+
print(f"Created account. Address: {account.address}.")
|
138
|
+
|
139
|
+
named_account = await cdp.solana.get_or_create_account(name="MyAccount")
|
140
|
+
print(f"Created account with name {named_account.name}.")
|
141
|
+
|
142
|
+
asyncio.run(main())
|
143
|
+
```
|
144
|
+
</CodeGroup>
|
145
|
+
|
146
|
+
## Managing Existing Accounts
|
147
|
+
|
148
|
+
Once you've created accounts, you can retrieve, list, and update them as needed.
|
149
|
+
|
150
|
+
### Getting Accounts by Address or Name
|
151
|
+
|
152
|
+
You can retrieve a specific account by its address or name using the `getAccount` method.
|
153
|
+
|
154
|
+
<CodeGroup>
|
155
|
+
```ts TypeScript lines wrap
|
156
|
+
import { CdpClient } from "@coinbase/cdp-sdk";
|
157
|
+
import "dotenv/config";
|
158
|
+
|
159
|
+
const cdp = new CdpClient();
|
160
|
+
|
161
|
+
// Returns the account with the given address, if it exists.
|
162
|
+
const account = await cdp.evm.getAccount({
|
163
|
+
address: "0x1234567890123456789012345678901234567890"
|
164
|
+
});
|
165
|
+
|
166
|
+
// Returns the account with the given name, if it exists.
|
167
|
+
const namedAccount = await cdp.evm.getAccount({
|
168
|
+
name: "MyAccount"
|
169
|
+
});
|
170
|
+
```
|
171
|
+
|
172
|
+
```python Python lines wrap
|
173
|
+
import asyncio
|
174
|
+
from cdp import CdpClient
|
175
|
+
import dotenv
|
176
|
+
|
177
|
+
async def main():
|
178
|
+
async with CdpClient() as cdp:
|
179
|
+
# Returns the account with the given address, if it exists.
|
180
|
+
account = await cdp.evm.get_account(
|
181
|
+
address="0x1234567890123456789012345678901234567890"
|
182
|
+
)
|
183
|
+
|
184
|
+
# Returns the account with the given name, if it exists.
|
185
|
+
named_account = await cdp.evm.get_account(
|
186
|
+
name="MyAccount"
|
187
|
+
)
|
188
|
+
```
|
189
|
+
</CodeGroup>
|
190
|
+
|
191
|
+
### Listing All Accounts
|
192
|
+
|
193
|
+
You can list all accounts of a specific type in a single CDP project by calling the `listAccounts` method:
|
194
|
+
|
195
|
+
<CodeGroup>
|
196
|
+
```ts TypeScript lines wrap [expandable]
|
197
|
+
import { CdpClient } from "@coinbase/cdp-sdk";
|
198
|
+
import "dotenv/config";
|
199
|
+
|
200
|
+
const cdp = new CdpClient();
|
201
|
+
let response = await cdp.evm.listAccounts();
|
202
|
+
|
203
|
+
// Paginate through all accounts.
|
204
|
+
while (true) {
|
205
|
+
for (const account of response.accounts) {
|
206
|
+
console.log('EVM account:', account.address);
|
207
|
+
}
|
208
|
+
|
209
|
+
if (!response.nextPageToken) break;
|
210
|
+
|
211
|
+
response = await cdp.evm.listAccounts({
|
212
|
+
pageToken: response.nextPageToken
|
213
|
+
});
|
214
|
+
}
|
215
|
+
```
|
216
|
+
|
217
|
+
```python Python lines wrap [expandable]
|
218
|
+
import asyncio
|
219
|
+
from cdp import CdpClient
|
220
|
+
import dotenv
|
221
|
+
|
222
|
+
dotenv.load_dotenv()
|
223
|
+
|
224
|
+
async def main():
|
225
|
+
async with CdpClient() as cdp:
|
226
|
+
response = await cdp.evm.list_accounts()
|
227
|
+
|
228
|
+
while True:
|
229
|
+
for account in response.accounts:
|
230
|
+
print('EVM account:', account.address)
|
231
|
+
|
232
|
+
if not response.next_page_token:
|
233
|
+
break
|
234
|
+
|
235
|
+
response = await cdp.evm.list_accounts(
|
236
|
+
page_token=response.next_page_token
|
237
|
+
)
|
238
|
+
|
239
|
+
asyncio.run(main())
|
240
|
+
```
|
241
|
+
</CodeGroup>
|
242
|
+
|
243
|
+
### Updating Accounts
|
244
|
+
|
245
|
+
After creating an account, you can modify various properties including the account name and attach policies to govern account behavior.
|
246
|
+
|
247
|
+
#### Changing Account Names
|
248
|
+
|
249
|
+
You can change the name of an existing account using the `updateAccount` method:
|
250
|
+
|
251
|
+
<CodeGroup>
|
252
|
+
```ts TypeScript lines wrap
|
253
|
+
import { CdpClient } from "@coinbase/cdp-sdk";
|
254
|
+
import "dotenv/config";
|
255
|
+
|
256
|
+
const cdp = new CdpClient();
|
257
|
+
|
258
|
+
// Get an existing account
|
259
|
+
const account = await cdp.evm.getOrCreateAccount({
|
260
|
+
name: "original-name"
|
261
|
+
});
|
262
|
+
console.log(`Original account name: ${account.name}`);
|
263
|
+
|
264
|
+
// Update the account name
|
265
|
+
const updatedAccount = await cdp.evm.updateAccount({
|
266
|
+
address: account.address,
|
267
|
+
update: {
|
268
|
+
name: "new-name",
|
269
|
+
},
|
270
|
+
});
|
271
|
+
console.log(`Updated account name: ${updatedAccount.name}`);
|
272
|
+
```
|
273
|
+
|
274
|
+
```python Python lines wrap
|
275
|
+
import asyncio
|
276
|
+
from cdp import CdpClient
|
277
|
+
import dotenv
|
278
|
+
|
279
|
+
dotenv.load_dotenv()
|
280
|
+
|
281
|
+
async def main():
|
282
|
+
async with CdpClient() as cdp:
|
283
|
+
# Get an existing account
|
284
|
+
account = await cdp.evm.get_or_create_account(name="original-name")
|
285
|
+
print(f"Original account name: {account.name}")
|
286
|
+
|
287
|
+
# Update the account name
|
288
|
+
updated_account = await cdp.evm.update_account(
|
289
|
+
address=account.address,
|
290
|
+
update={
|
291
|
+
"name": "new-name",
|
292
|
+
},
|
293
|
+
)
|
294
|
+
print(f"Updated account name: {updated_account.name}")
|
295
|
+
|
296
|
+
asyncio.run(main())
|
297
|
+
```
|
298
|
+
</CodeGroup>
|
299
|
+
|
300
|
+
#### Attaching Policies
|
301
|
+
|
302
|
+
You can attach [policies](/wallet-api/v2/using-the-wallet-api/policies) to accounts to govern their behavior, such as restricting transactions to specific addresses or limiting transaction values. Policies can be attached during account creation or added later using the `updateAccount` method:
|
303
|
+
|
304
|
+
<CodeGroup>
|
305
|
+
```ts TypeScript lines wrap
|
306
|
+
import { CdpClient } from "@coinbase/cdp-sdk";
|
307
|
+
import "dotenv/config";
|
308
|
+
|
309
|
+
const cdp = new CdpClient();
|
310
|
+
|
311
|
+
// Get an existing account
|
312
|
+
const account = await cdp.evm.getOrCreateAccount({
|
313
|
+
name: "policy-account"
|
314
|
+
});
|
315
|
+
|
316
|
+
const policyId = "your-policy-id"; // Replace with your actual policy ID
|
317
|
+
|
318
|
+
// Attach a policy to the account
|
319
|
+
const updatedAccount = await cdp.evm.updateAccount({
|
320
|
+
address: account.address,
|
321
|
+
update: {
|
322
|
+
accountPolicy: policyId,
|
323
|
+
},
|
324
|
+
});
|
325
|
+
console.log(`Updated account ${updatedAccount.address} with policy: ${updatedAccount.policies}`);
|
326
|
+
```
|
327
|
+
|
328
|
+
```python Python lines wrap
|
329
|
+
import asyncio
|
330
|
+
from cdp import CdpClient
|
331
|
+
import dotenv
|
332
|
+
|
333
|
+
dotenv.load_dotenv()
|
334
|
+
|
335
|
+
async def main():
|
336
|
+
async with CdpClient() as cdp:
|
337
|
+
# Get an existing account
|
338
|
+
account = await cdp.evm.get_or_create_account(name="policy-account")
|
339
|
+
|
340
|
+
policy_id = "your-policy-id" # Replace with your actual policy ID
|
341
|
+
|
342
|
+
# Attach a policy to the account
|
343
|
+
updated_account = await cdp.evm.update_account(
|
344
|
+
address=account.address,
|
345
|
+
update={
|
346
|
+
"account_policy": policy_id,
|
347
|
+
},
|
348
|
+
)
|
349
|
+
print(f"Updated account {updated_account.address} with policy: {updated_account.policies}")
|
350
|
+
|
351
|
+
asyncio.run(main())
|
352
|
+
```
|
353
|
+
</CodeGroup>
|
354
|
+
|
355
|
+
<Note>
|
356
|
+
To learn more about creating and managing policies, see the [Policies](/wallet-api/v2/using-the-wallet-api/policies) documentation.
|
357
|
+
</Note>
|
358
|
+
|
359
|
+
### Account Manager UI
|
360
|
+
|
361
|
+
You can also manage account in the [CDP Portal Account Manager UI](https://portal.cdp.coinbase.com/products/wallet-api/accounts). From here you can
|
362
|
+
view your accounts by chain and type, and you can click into an account to view more information like balances and policies.
|
363
|
+
|
364
|
+
<Frame>
|
365
|
+
<img src="https://mintlify.s3.us-west-1.amazonaws.com/coinbase-prod/wallet-api/images/account-manager-ui.png" alt="Account Manager UI" />
|
366
|
+
</Frame>
|