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.
@@ -0,0 +1,122 @@
1
+ # Fund Accounts
2
+
3
+ ## Overview
4
+
5
+ With the CDP SDK, you can fund your account from fiat currency (eg. USD) in a bank account with a single API call. This method is currently limited to US-based individuals using US debit card (without 3DS verification) payment methods configured in a Coinbase account.
6
+ We will add support for businesses and for additional payment methods soon. This method currently supports funding accounts with USDC and ETH on the Base and Ethereum networks. Want more? [Get in touch](https://calendar.app.google/X6VRM3qwcSbUDQ1f8) for early access!
7
+
8
+ <Tip>
9
+ Start by [creating a Coinbase account](https://login.coinbase.com/pick-your-account) if you don't already have one, and add payment method(s).
10
+ </Tip>
11
+
12
+ ## Account Funding API (Beta)
13
+
14
+ To use the Account Funding API, you need a Coinbase account with a US debit card (non-3DS) payment method added. If you have multiple debit cards set up, this method will use the first non-3DS, active, verified card you added.
15
+
16
+ The Account Funding API supports both EOA accounts and Smart Accounts.
17
+
18
+ ### Limits
19
+
20
+ Account funding limits are the same as your [Coinbase account limits](https://help.coinbase.com/en/coinbase/trading-and-funding/buying-selling-or-converting-crypto/limits-and-account-levels).
21
+
22
+ ### Get a quote
23
+
24
+ Use the `quoteFund` method to generate quotes for converting between fiat currency and crypto tokens with all associated fees. The `quoteFund` method returns a quote object, which expires in 10 minutes, with estimated network and exchange fees associated with your account funding operation. Save on fees with [Coinbase One](https://www.coinbase.com/one).
25
+
26
+ <CodeGroup>
27
+ ```ts TypeScript lines wrap
28
+ const account = await cdp.evm.getOrCreateAccount({ name: "account" });
29
+
30
+ const quote = await account.quoteFund({
31
+ network: "base",
32
+ token: "eth",
33
+ amount: 500000000000000n, // 0.0005 eth
34
+ });
35
+
36
+ // Parameters of the quote you can inspect to see if you want to execute it.
37
+ console.log("Fiat amount: ", quote.fiatAmount)
38
+ console.log("Fiat currency: ", quote.fiatCurrency)
39
+ for (const fee of quote.fees) {
40
+ console.log("Fee type: ", fee.type) // network_fee or exchange_fee
41
+ console.log("Fee amount: ", fee.amount)
42
+ console.log("Fee currency: ", fee.currency)
43
+ }
44
+ ```
45
+
46
+ ```python Python lines wrap
47
+ account = await cdp.evm.get_or_create_account(name="account")
48
+
49
+ quote = await account.quote_fund(
50
+ network="base",
51
+ token="eth",
52
+ amount=500000000000000, # 0.0005 eth
53
+ )
54
+ # Parameters of the quote you can inspect to see if you want to execute it.
55
+ print("Fiat amount: ", quote.fiat_amount)
56
+ print("Fiat currency: ", quote.fiat_currency)
57
+ for fee in quote.fees:
58
+ print("Fee type: ", fee.type) # network_fee or exchange_fee
59
+ print("Fee amount: ", fee.amount)
60
+ print("Fee currency: ", fee.currency)
61
+ ```
62
+ </CodeGroup>
63
+
64
+ ### Execute a quote
65
+
66
+ If you have already generated a quote, you can simply execute it to initiate account funding:
67
+
68
+ <CodeGroup>
69
+ ```ts TypeScript lines wrap
70
+ // Execute the previously quoted account funding operation
71
+ const fundOperationResult = await quote.execute();
72
+
73
+ // Wait for the funding operation to settle
74
+ const completedTransfer = await account.waitForFundOperationReceipt({
75
+ transferId: fundOperationResult.id
76
+ });
77
+ ```
78
+
79
+ ```python Python lines wrap
80
+ # Execute the previously quoted account funding operation
81
+ fund_operation_result = await quote.execute()
82
+
83
+ # Wait for the funding operation to settle
84
+ completed_transfer = await account.wait_for_fund_operation_receipt(
85
+ transfer_id=fund_operation_result.id,
86
+ )
87
+ ```
88
+ </CodeGroup>
89
+
90
+ ### Executing directly without a quote
91
+
92
+ **If you want to directly execute an account funding operation without first getting a quote**, you may directly call the fund method specifying the amount and crypto asset.
93
+
94
+ <CodeGroup>
95
+ ```ts TypeScript lines wrap
96
+ // Initiate the funding operation
97
+ const fundOperation = await account.fund({
98
+ network: "base",
99
+ token: "eth",
100
+ amount: 500000000000000n, // 0.0005 eth
101
+ });
102
+
103
+ // Wait for the funding operation to settle
104
+ const completedTransfer = await account.waitForFundOperationReceipt({
105
+ transferId: fundOperation.id,
106
+ });
107
+ ```
108
+
109
+ ```python Python lines wrap
110
+ # Initiate the funding operation
111
+ fund_operation = await account.fund(
112
+ network="base",
113
+ token="eth",
114
+ amount=500000000000000, # 0.0005 eth
115
+ )
116
+
117
+ # Wait for the funding operation to settle
118
+ completed_transfer = await account.wait_for_fund_operation_receipt(
119
+ transfer_id=fund_operation.id,
120
+ )
121
+ ```
122
+ </CodeGroup>
@@ -0,0 +1,273 @@
1
+ # Importing Accounts
2
+
3
+ ## Overview
4
+
5
+ The CDP Wallet API offers a secure method for creating EVM and Solana Accounts from imported private keys.
6
+
7
+ The import flow is end-to-end encrypted between the CDP SDK and the [TEE](/wallet-api/v2/introduction/security#tee-architecture), ensuring that keys are never exposed outside of the secure enclave during the request.
8
+ Encrypted by the SDK in a way that only the TEE can decrypt the keys, this process enables seamless and secure import of your keys into v2 accounts.
9
+
10
+ This feature can be used to import wallets from external wallet providers and the [v1 Wallet API](/wallet-api/v1/introduction/welcome).
11
+
12
+ ## EVM Accounts: Import from external wallet providers
13
+
14
+ You can import private keys from other wallet providers by exporting them as raw, hex-encoded 32-byte strings.
15
+
16
+ To complete the import, use `importAccount` in TypeScript or `import_account` in the Python CDP SDK.
17
+ Only private key import is supported. To import an HD Wallet, derive individual private keys from the seed and import them one by one.
18
+
19
+ <CodeGroup>
20
+ ```ts TypeScript lines wrap
21
+ import { CdpClient } from "@coinbase/cdp-sdk";
22
+ import dotenv from "dotenv";
23
+
24
+ dotenv.config();
25
+
26
+ const cdp = new CdpClient();
27
+ const account = await cdp.evm.importAccount({
28
+ privateKey: "0x0123456789abcdef...",
29
+ name: "ExternalWalletImportedAccount",
30
+ });
31
+ console.log("Imported account: ", account.address);
32
+ ```
33
+
34
+ ```python Python lines wrap
35
+ import asyncio
36
+ from cdp import CdpClient
37
+ from dotenv import load_dotenv
38
+
39
+ load_dotenv()
40
+
41
+ async def main():
42
+ async with CdpClient() as cdp:
43
+ account = await cdp.evm.import_account(
44
+ private_key="0x0123456789abcdef...",
45
+ name="ExternalWalletImportedAccount",
46
+ )
47
+ print("Imported account: ", account.address)
48
+
49
+ asyncio.run(main())
50
+ ```
51
+ </CodeGroup>
52
+
53
+ ## Solana Accounts: Import from external wallet providers
54
+
55
+ Here's an example of how to import a Solana account with a base58-encoded private key from a wallet provider like Phantom.
56
+
57
+ <CodeGroup>
58
+ ```ts TypeScript lines wrap
59
+ import { CdpClient } from "@coinbase/cdp-sdk";
60
+ import dotenv from "dotenv";
61
+
62
+ dotenv.config();
63
+
64
+ const cdp = new CdpClient();
65
+ const account = await cdp.solana.importAccount({
66
+ privateKey: "4YFq9y5f5hi77Bq8kDCE6VgqoAq...",
67
+ name: "ExternalWalletImportedAccount",
68
+ });
69
+ console.log("Imported account: ", account.address);
70
+ ```
71
+
72
+ ```python Python lines wrap
73
+ import asyncio
74
+ from cdp import CdpClient
75
+ from dotenv import load_dotenv
76
+
77
+ load_dotenv()
78
+
79
+ async def main():
80
+ async with CdpClient() as cdp:
81
+ account = await cdp.solana.import_account(
82
+ private_key="4YFq9y5f5hi77Bq8kDCE6VgqoAq...",
83
+ name="ExternalWalletImportedAccount",
84
+ )
85
+ print("Imported account: ", account.address)
86
+
87
+ asyncio.run(main())
88
+ ```
89
+ </CodeGroup>
90
+
91
+ You can also import a Solana account using the raw 32-byte private key array.
92
+
93
+ <CodeGroup>
94
+ ```ts TypeScript lines wrap
95
+ import { CdpClient } from "@coinbase/cdp-sdk";
96
+ import dotenv from "dotenv";
97
+
98
+ dotenv.config();
99
+
100
+ const keypair = Keypair.generate();
101
+ const privateKeyBytes32 = keypair.secretKey.subarray(0, 32);
102
+
103
+ const account = await cdp.solana.importAccount({
104
+ privateKey: privateKeyBytes32,
105
+ name: "BytesAccount32",
106
+ });
107
+ console.log("Imported account: ", account.address);
108
+ ```
109
+
110
+ ```python Python lines wrap
111
+ import asyncio
112
+ from cdp import CdpClient
113
+ from dotenv import load_dotenv
114
+
115
+ load_dotenv()
116
+
117
+ async def main():
118
+ async with CdpClient() as cdp:
119
+ keypair = Keypair.generate()
120
+ private_key_bytes32 = keypair.secret_key[:32]
121
+
122
+ account = await cdp.solana.import_account(
123
+ private_key=private_key_bytes32,
124
+ name="BytesAccount32",
125
+ )
126
+ print("Imported account: ", account.address)
127
+
128
+ asyncio.run(main())
129
+ ```
130
+ </CodeGroup>
131
+
132
+ ## Import [developer-managed v1 Wallets](/wallet-api/v1/concepts/wallets/#developer-managed-wallets)
133
+
134
+ A key difference between v1 wallets and v2 accounts is that v1 wallets are HD Wallets, while v2 accounts are single-address accounts.
135
+ Import each address from your v1 wallet as an individual v2 account, following the steps below.
136
+
137
+ First, set up a new project and install dependencies
138
+
139
+ ```ts TypeScript lines wrap
140
+ mkdir import-example && cd import-example
141
+ npm init -y && npm pkg set type="module"
142
+ npm install @coinbase/coinbase-sdk @coinbase/cdp-sdk dotenv
143
+ ```
144
+
145
+ The below script does the following to import from v1 wallets to v2:
146
+
147
+ 1. Export private key of v1 address using v1 SDK
148
+ 2. Import private keys as a v2 account using v2 SDK
149
+
150
+ ```ts TypeScript lines wrap [expandable]
151
+ // Step 1: Export private keys of v1 address.
152
+ import { Coinbase, Wallet } from "@coinbase/coinbase-sdk";
153
+ import { CdpClient } from "@coinbase/cdp-sdk";
154
+ import dotenv from "dotenv";
155
+
156
+ dotenv.config();
157
+
158
+ // Change this to the path of your API key file downloaded from CDP portal.
159
+ Coinbase.configureFromJson({ filePath: "~/Downloads/cdp_api_key.json" });
160
+
161
+ // Add the ID of the wallet and its seed to import.
162
+ const wallet_id = ''
163
+ const seed = ''
164
+
165
+ // Fetch the wallet and set the seed.
166
+ let wallet = await Wallet.fetch(wallet_id);
167
+ // You can also load the seed using loadSeedFromFile call.
168
+ await wallet.setSeed(seed);
169
+
170
+ console.log(`Wallet successfully fetched: `, wallet.toString());
171
+
172
+ // Export private key of the default address.
173
+ let address = await wallet.getDefaultAddress();
174
+ let privateKey = address.export();
175
+
176
+ // Step 2: Import exported private key as a v2 account.
177
+ const cdp = new CdpClient();
178
+ const account = await cdp.evm.importAccount({
179
+ privateKey: privateKey,
180
+ name: "ImportedAccount",
181
+ });
182
+
183
+ console.log("Imported account: ", account.address);
184
+ ```
185
+
186
+ ## Import [Coinbase-managed v1 Wallets](/wallet-api/v1/concepts/wallets/#coinbase-managed-wallets)
187
+
188
+ Coinbase-Managed v1 wallets use Multi-Party Computation to split the private key shares between Coinbase and the developer.
189
+
190
+ These wallets do not support private key export today.
191
+ Therefore, to migrate these wallets, you must create a new v2 account and transfer funds onchain from your existing v1 addresses.
192
+ The v1 SDK's [gasless sends](/wallet-api/v1/concepts/transfers#gasless-transfers) feature can be used for a zero-cost migration.
193
+
194
+ Create new v2 accounts for each address in your v1 wallet and transfer funds to them using the steps below:
195
+
196
+ 1. Fetch the v1 wallet using v1 SDK
197
+ 2. Create new v2 account using v2 SDK
198
+ 3. Send funds from v1 address to the new v2 account using v1 SDK
199
+
200
+ ```typescript index.js lines wrap [expandable]
201
+ import { Coinbase, Wallet } from "@coinbase/coinbase-sdk";
202
+ import { CdpClient } from "@coinbase/cdp-sdk";
203
+ import dotenv from "dotenv";
204
+
205
+ dotenv.config();
206
+
207
+ // Step 1: Fetch the v1 wallet.
208
+ // Change this to the path of your API key file downloaded from CDP portal.
209
+ Coinbase.configureFromJson({ filePath: "~/Downloads/cdp_api_key.json" });
210
+ Coinbase.useServerSigner = true;
211
+
212
+ // Add the ID of the v1 wallet.
213
+ const wallet_id = ''
214
+ let v1_wallet = await Wallet.fetch(wallet_id);
215
+
216
+ console.log(`Wallet successfully fetched: `, v1_wallet.toString());
217
+
218
+ // Step 2: Create a new v2 account.
219
+ const cdp = new CdpClient();
220
+
221
+ let v2_account = await cdp.evm.createAccount({
222
+ name: "NewAccount",
223
+ });
224
+
225
+ console.log(`Created account: ${v2_account} successfully`);
226
+
227
+ let balance = await v1_wallet.getBalance(Coinbase.assets.Usdc);
228
+ let transfer;
229
+
230
+ // Step 3: Send funds from v1 address to v2 account using gasless sends feature.
231
+ try {
232
+ transfer = await v1_wallet.createTransfer({
233
+ amount: balance,
234
+ assetId: Coinbase.assets.Usdc,
235
+ destination: v2_account.address,
236
+ gasless: true,
237
+ });
238
+ } catch (e) {
239
+ console.error(`Error transferring funds: ${e}`)
240
+ }
241
+
242
+ // Wait for the transfer to land on-chain.
243
+ try {
244
+ transfer = await transfer.wait();
245
+ } catch (err) {
246
+ if (err instanceof TimeoutError) {
247
+ console.log("Waiting for transfer timed out");
248
+ } else {
249
+ console.error("Error while waiting for transfer to complete: ", error);
250
+ }
251
+ }
252
+
253
+ // Check if transfer successfully completed on-chain.
254
+ if (transfer.getStatus() === 'complete') {
255
+ console.log('Transfer completed on-chain: ', transfer.toString());
256
+ } else {
257
+ console.error('Transfer failed on-chain: ', transfer.toString());
258
+ }
259
+ ```
260
+
261
+ ## Video: Watch and learn
262
+
263
+ **Watch this video for a walkthrough of importing keys:**
264
+
265
+ <Frame>
266
+ <iframe width="560" height="315" src="https://www.youtube.com/embed/sRQ7SA0pSdw" title="Importing Keys Walkthrough" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen />
267
+ </Frame>
268
+
269
+ ## What to read next
270
+
271
+ * [**v2 Wallet Security**](/wallet-api/v2/introduction/security): Learn more about the security features of the CDP v2 Wallet API.
272
+ * [**Policies**](/wallet-api/v2/using-the-wallet-api/policies): Learn more about governing behavior of v2 accounts.
273
+ * [**Exporting Accounts**](/wallet-api/v2/using-the-wallet-api/export-accounts): Learn more about exporting EVM and Solana accounts.