@coinbase/agentkit 0.8.1 → 0.9.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 +382 -230
- package/dist/action-providers/cdp/cdpApiActionProvider.d.ts +15 -15
- package/dist/action-providers/cdp/cdpApiActionProvider.js +110 -63
- package/dist/action-providers/cdp/cdpApiActionProvider.test.js +205 -124
- package/dist/action-providers/cdp/index.d.ts +0 -1
- package/dist/action-providers/cdp/index.js +0 -1
- package/dist/action-providers/cdp/schemas.d.ts +9 -70
- package/dist/action-providers/cdp/schemas.js +12 -61
- package/dist/action-providers/cdp-legacy/index.d.ts +3 -0
- package/dist/action-providers/cdp-legacy/index.js +19 -0
- package/dist/action-providers/cdp-legacy/legacyCdpApiActionProvider.d.ts +45 -0
- package/dist/action-providers/cdp-legacy/legacyCdpApiActionProvider.js +130 -0
- package/dist/action-providers/cdp-legacy/legacyCdpApiActionProvider.test.js +146 -0
- package/dist/action-providers/{cdp/cdpWalletActionProvider.d.ts → cdp-legacy/legacyCdpWalletActionProvider.d.ts} +8 -8
- package/dist/action-providers/{cdp/cdpWalletActionProvider.js → cdp-legacy/legacyCdpWalletActionProvider.js} +14 -14
- package/dist/action-providers/{cdp/cdpWalletActionProvider.test.js → cdp-legacy/legacyCdpWalletActionProvider.test.js} +3 -3
- package/dist/action-providers/cdp-legacy/schemas.d.ts +91 -0
- package/dist/action-providers/cdp-legacy/schemas.js +77 -0
- package/dist/action-providers/erc20/erc20ActionProvider.js +1 -1
- package/dist/action-providers/index.d.ts +2 -1
- package/dist/action-providers/index.js +2 -1
- package/dist/action-providers/jupiter/jupiterActionProvider.test.js +2 -4
- package/dist/action-providers/vaultsfyi/api/historicalData.d.ts +31 -0
- package/dist/action-providers/vaultsfyi/api/historicalData.js +44 -0
- package/dist/action-providers/vaultsfyi/api/vaults.d.ts +38 -10
- package/dist/action-providers/vaultsfyi/api/vaults.js +19 -1
- package/dist/action-providers/vaultsfyi/schemas.d.ts +38 -3
- package/dist/action-providers/vaultsfyi/schemas.js +35 -3
- package/dist/action-providers/vaultsfyi/utils.d.ts +64 -0
- package/dist/action-providers/vaultsfyi/utils.js +53 -0
- package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.d.ts +18 -2
- package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.js +87 -20
- package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.test.js +165 -0
- package/dist/action-providers/x402/index.d.ts +1 -0
- package/dist/action-providers/{cdp-v2 → x402}/index.js +1 -2
- package/dist/action-providers/x402/schemas.d.ts +77 -0
- package/dist/action-providers/x402/schemas.js +79 -0
- package/dist/action-providers/x402/x402ActionProvider.d.ts +55 -0
- package/dist/action-providers/x402/x402ActionProvider.js +288 -0
- package/dist/action-providers/x402/x402ActionProvider.test.js +322 -0
- package/dist/agentkit.d.ts +1 -0
- package/dist/agentkit.js +3 -2
- package/dist/wallet-providers/{cdpV2EvmWalletProvider.d.ts → cdpEvmWalletProvider.d.ts} +16 -7
- package/dist/wallet-providers/{cdpV2EvmWalletProvider.js → cdpEvmWalletProvider.js} +50 -39
- package/dist/wallet-providers/{cdpV2EvmWalletProvider.test.js → cdpEvmWalletProvider.test.js} +7 -7
- package/dist/wallet-providers/{cdpV2Shared.d.ts → cdpShared.d.ts} +15 -4
- package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +115 -0
- package/dist/wallet-providers/cdpSmartWalletProvider.js +263 -0
- package/dist/wallet-providers/cdpSmartWalletProvider.test.js +287 -0
- package/dist/wallet-providers/{cdpV2SolanaWalletProvider.d.ts → cdpSolanaWalletProvider.d.ts} +16 -7
- package/dist/wallet-providers/{cdpV2SolanaWalletProvider.js → cdpSolanaWalletProvider.js} +43 -32
- package/dist/wallet-providers/cdpSolanaWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/{cdpV2SolanaWalletProvider.test.js → cdpSolanaWalletProvider.test.js} +7 -7
- package/dist/wallet-providers/index.d.ts +6 -6
- package/dist/wallet-providers/index.js +6 -6
- package/dist/wallet-providers/{smartWalletProvider.d.ts → legacyCdpSmartWalletProvider.d.ts} +3 -3
- package/dist/wallet-providers/{smartWalletProvider.js → legacyCdpSmartWalletProvider.js} +21 -21
- package/dist/wallet-providers/legacyCdpSmartWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/{smartWalletProvider.test.js → legacyCdpSmartWalletProvider.test.js} +2 -2
- package/dist/wallet-providers/{cdpWalletProvider.d.ts → legacyCdpWalletProvider.d.ts} +15 -11
- package/dist/wallet-providers/{cdpWalletProvider.js → legacyCdpWalletProvider.js} +72 -70
- package/dist/wallet-providers/legacyCdpWalletProvider.test.d.ts +1 -0
- package/dist/wallet-providers/{cdpWalletProvider.test.js → legacyCdpWalletProvider.test.js} +10 -10
- package/package.json +8 -5
- package/dist/action-providers/cdp-v2/cdpApiV2ActionProvider.d.ts +0 -34
- package/dist/action-providers/cdp-v2/cdpApiV2ActionProvider.js +0 -98
- package/dist/action-providers/cdp-v2/index.d.ts +0 -2
- package/dist/action-providers/cdp-v2/schemas.d.ts +0 -11
- package/dist/action-providers/cdp-v2/schemas.js +0 -13
- package/dist/wallet-providers/cdpV2WalletProvider.d.ts +0 -35
- package/dist/wallet-providers/cdpV2WalletProvider.js +0 -42
- /package/dist/action-providers/{cdp → cdp-legacy}/constants.d.ts +0 -0
- /package/dist/action-providers/{cdp → cdp-legacy}/constants.js +0 -0
- /package/dist/action-providers/{cdp/cdpWalletActionProvider.test.d.ts → cdp-legacy/legacyCdpApiActionProvider.test.d.ts} +0 -0
- /package/dist/{wallet-providers/cdpV2EvmWalletProvider.test.d.ts → action-providers/cdp-legacy/legacyCdpWalletActionProvider.test.d.ts} +0 -0
- /package/dist/{wallet-providers/cdpV2SolanaWalletProvider.test.d.ts → action-providers/x402/x402ActionProvider.test.d.ts} +0 -0
- /package/dist/wallet-providers/{cdpWalletProvider.test.d.ts → cdpEvmWalletProvider.test.d.ts} +0 -0
- /package/dist/wallet-providers/{cdpV2Shared.js → cdpShared.js} +0 -0
- /package/dist/wallet-providers/{smartWalletProvider.test.d.ts → cdpSmartWalletProvider.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -18,14 +18,27 @@ AgentKit is a framework for easily enabling AI agents to take actions onchain. I
|
|
|
18
18
|
- [Adding Actions to your Action Provider that use a Wallet Provider](#adding-actions-to-your-action-provider-that-use-a-wallet-provider)
|
|
19
19
|
- [Adding an Action Provider to your AgentKit instance](#adding-an-action-provider-to-your-agentkit-instance)
|
|
20
20
|
- [EVM Wallet Providers](#evm-wallet-providers)
|
|
21
|
-
- [
|
|
22
|
-
|
|
21
|
+
- [CdpEvmWalletProvider](#cdpevmwalletprovider)
|
|
22
|
+
- [Basic Configuration](#basic-configuration)
|
|
23
|
+
- [Using an existing wallet](#using-an-existing-wallet)
|
|
24
|
+
- [Creating a new wallet](#creating-a-new-wallet)
|
|
25
|
+
- [Environment Variables](#environment-variables)
|
|
26
|
+
- [Exporting a wallet](#exporting-a-wallet)
|
|
27
|
+
- [CdpSmartWalletProvider](#cdpsmartwalletprovider)
|
|
28
|
+
- [Basic Configuration](#basic-configuration-1)
|
|
29
|
+
- [Using an Existing Smart Wallet](#using-an-existing-smart-wallet)
|
|
30
|
+
- [Specifying an Owner Account](#specifying-an-owner-account)
|
|
31
|
+
- [Creating a New Smart Wallet](#creating-a-new-smart-wallet)
|
|
32
|
+
- [Environment Variables](#environment-variables-1)
|
|
33
|
+
- [Exporting Smart Wallet Information](#exporting-smart-wallet-information)
|
|
34
|
+
- [Key Differences from Regular Wallets](#key-differences-from-regular-wallets)
|
|
35
|
+
- [LegacyCdpWalletProvider](#legacycdpwalletprovider)
|
|
23
36
|
- [Network Configuration](#network-configuration)
|
|
24
37
|
- [Configuring from an existing CDP API Wallet](#configuring-from-an-existing-cdp-api-wallet)
|
|
25
38
|
- [Configuring from a mnemonic phrase](#configuring-from-a-mnemonic-phrase)
|
|
26
39
|
- [Exporting a wallet](#exporting-a-wallet)
|
|
27
40
|
- [Importing a wallet from WalletData JSON string](#importing-a-wallet-from-walletdata-json-string)
|
|
28
|
-
- [Configuring gas parameters](#configuring-
|
|
41
|
+
- [Configuring gas parameters](#configuring-legacycdpwalletprovider-gas-parameters)
|
|
29
42
|
- [ViemWalletProvider](#viemwalletprovider)
|
|
30
43
|
- [Configuring gas parameters](#configuring-viemwalletprovider-gas-parameters)
|
|
31
44
|
- [PrivyWalletProvider](#privywalletprovider)
|
|
@@ -37,7 +50,7 @@ AgentKit is a framework for easily enabling AI agents to take actions onchain. I
|
|
|
37
50
|
- [Configuring from PrivyWalletProvider](#configuring-from-privywalletprovider)
|
|
38
51
|
- [Configuring from ViemWalletProvider](#configuring-from-viemwalletprovider)
|
|
39
52
|
- [SVM Wallet Providers](#svm-wallet-providers)
|
|
40
|
-
- [
|
|
53
|
+
- [CdpSolanaWalletProvider](#cdpsolanawalletprovider)
|
|
41
54
|
- [SolanaKeypairWalletProvider](#solanakeypairwalletprovider)
|
|
42
55
|
- [Network Configuration](#solana-network-configuration)
|
|
43
56
|
- [RPC URL Configuration](#rpc-url-configuration)
|
|
@@ -49,7 +62,8 @@ AgentKit is a framework for easily enabling AI agents to take actions onchain. I
|
|
|
49
62
|
|
|
50
63
|
## Getting Started
|
|
51
64
|
|
|
52
|
-
|
|
65
|
+
_Prerequisites_:
|
|
66
|
+
|
|
53
67
|
- [Node.js 18+](https://nodejs.org/en/download/)
|
|
54
68
|
- [CDP Secret API Key](https://docs.cdp.coinbase.com/get-started/docs/cdp-api-keys#creating-secret-api-keys)
|
|
55
69
|
|
|
@@ -66,7 +80,7 @@ npm install @coinbase/agentkit
|
|
|
66
80
|
```typescript
|
|
67
81
|
const agentKit = await AgentKit.from({
|
|
68
82
|
cdpApiKeyId: "CDP API KEY NAME",
|
|
69
|
-
|
|
83
|
+
cdpApiKeySecret: "CDP API KEY SECRET",
|
|
70
84
|
});
|
|
71
85
|
```
|
|
72
86
|
|
|
@@ -77,7 +91,7 @@ If no wallet or action provider are specified, the agent will use the `CdpWallet
|
|
|
77
91
|
```typescript
|
|
78
92
|
const agentKit = await AgentKit.from({
|
|
79
93
|
cdpApiKeyId: "CDP API KEY NAME",
|
|
80
|
-
|
|
94
|
+
cdpApiKeySecret: "CDP API KEY SECRET",
|
|
81
95
|
});
|
|
82
96
|
```
|
|
83
97
|
|
|
@@ -87,13 +101,13 @@ const agentKit = await AgentKit.from({
|
|
|
87
101
|
import { CdpWalletProvider } from "@coinbase/agentkit";
|
|
88
102
|
|
|
89
103
|
const walletProvider = await CdpWalletProvider.configureWithWallet({
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
104
|
+
apiKeyId: "CDP API KEY NAME",
|
|
105
|
+
apiKeyPrivate: "CDP API KEY SECRET",
|
|
106
|
+
networkId: "base-mainnet",
|
|
93
107
|
});
|
|
94
108
|
|
|
95
109
|
const agentKit = await AgentKit.from({
|
|
96
|
-
|
|
110
|
+
walletProvider,
|
|
97
111
|
});
|
|
98
112
|
```
|
|
99
113
|
|
|
@@ -103,20 +117,21 @@ const agentKit = await AgentKit.from({
|
|
|
103
117
|
import { cdpApiActionProvider, pythActionProvider } from "@coinbase/agentkit";
|
|
104
118
|
|
|
105
119
|
const agentKit = await AgentKit.from({
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
120
|
+
walletProvider,
|
|
121
|
+
actionProviders: [
|
|
122
|
+
cdpApiActionProvider({
|
|
123
|
+
apiKeyId: "CDP API KEY NAME",
|
|
124
|
+
apiKeyPrivate: "CDP API KEY SECRET",
|
|
125
|
+
}),
|
|
126
|
+
pythActionProvider(),
|
|
127
|
+
],
|
|
114
128
|
});
|
|
115
129
|
```
|
|
116
130
|
|
|
117
131
|
### Use the agent's actions with a framework extension. For example, using LangChain + OpenAI.
|
|
118
132
|
|
|
119
|
-
|
|
133
|
+
_Prerequisites_:
|
|
134
|
+
|
|
120
135
|
- [OpenAI API Key](https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key)
|
|
121
136
|
- Set `OPENAI_API_KEY` environment variable.
|
|
122
137
|
|
|
@@ -132,16 +147,17 @@ import { ChatOpenAI } from "@langchain/openai";
|
|
|
132
147
|
const tools = await getLangChainTools(agentKit);
|
|
133
148
|
|
|
134
149
|
const llm = new ChatOpenAI({
|
|
135
|
-
|
|
150
|
+
model: "gpt-4o-mini",
|
|
136
151
|
});
|
|
137
152
|
|
|
138
153
|
const agent = createReactAgent({
|
|
139
|
-
|
|
140
|
-
|
|
154
|
+
llm,
|
|
155
|
+
tools,
|
|
141
156
|
});
|
|
142
157
|
```
|
|
143
158
|
|
|
144
159
|
## Action Providers
|
|
160
|
+
|
|
145
161
|
<details>
|
|
146
162
|
<summary><strong>Across</strong></summary>
|
|
147
163
|
<table width="100%">
|
|
@@ -165,27 +181,6 @@ const agent = createReactAgent({
|
|
|
165
181
|
</table>
|
|
166
182
|
</details>
|
|
167
183
|
<details>
|
|
168
|
-
<summary><strong>CDP Wallet</strong></summary>
|
|
169
|
-
<table width="100%">
|
|
170
|
-
<tr>
|
|
171
|
-
<td width="200"><code>deploy_contract</code></td>
|
|
172
|
-
<td width="768">Deploys a custom smart contract using specified Solidity version and constructor arguments.</td>
|
|
173
|
-
</tr>
|
|
174
|
-
<tr>
|
|
175
|
-
<td width="200"><code>deploy_nft</code></td>
|
|
176
|
-
<td width="768">Deploys a standard ERC-721 NFT contract with configurable name, symbol, and metadata URI.</td>
|
|
177
|
-
</tr>
|
|
178
|
-
<tr>
|
|
179
|
-
<td width="200"><code>deploy_token</code></td>
|
|
180
|
-
<td width="768">Deploys a standard ERC-20 token contract with configurable name, symbol, and initial supply.</td>
|
|
181
|
-
</tr>
|
|
182
|
-
<tr>
|
|
183
|
-
<td width="200"><code>trade</code></td>
|
|
184
|
-
<td width="768">Executes a token swap between two assets at current market rates on mainnet networks.</td>
|
|
185
|
-
</tr>
|
|
186
|
-
</table>
|
|
187
|
-
</details>
|
|
188
|
-
<details>
|
|
189
184
|
<summary><strong>Compound</strong></summary>
|
|
190
185
|
<table width="100%">
|
|
191
186
|
<tr>
|
|
@@ -418,6 +413,24 @@ const agent = createReactAgent({
|
|
|
418
413
|
</table>
|
|
419
414
|
</details>
|
|
420
415
|
<details>
|
|
416
|
+
<summary><strong>x402</strong></summary>
|
|
417
|
+
<table width="100%">
|
|
418
|
+
<tr>
|
|
419
|
+
<td width="200"><code>make_http_request</code></td>
|
|
420
|
+
<td width="768">Makes a basic HTTP request to an API endpoint. If the endpoint requires payment (returns 402),
|
|
421
|
+
it will return payment details that can be used on retry.</td>
|
|
422
|
+
</tr>
|
|
423
|
+
<tr>
|
|
424
|
+
<td width="200"><code>retry_http_request_with_x402</code></td>
|
|
425
|
+
<td width="768">Retries an HTTP request with x402 payment after receiving a 402 Payment Required response.</td>
|
|
426
|
+
</tr>
|
|
427
|
+
<tr>
|
|
428
|
+
<td width="200"><code>make_http_request_with_x402</code></td>
|
|
429
|
+
<td width="768">Combines make_http_request and retry_http_request_with_x402 into a single step.</td>
|
|
430
|
+
</tr>
|
|
431
|
+
</table>
|
|
432
|
+
</details>
|
|
433
|
+
<details>
|
|
421
434
|
<summary><strong>ZeroDev Wallet</strong></summary>
|
|
422
435
|
<table width="100%">
|
|
423
436
|
<tr>
|
|
@@ -436,12 +449,12 @@ import { ActionProvider, WalletProvider, Network } from "@coinbase/agentkit";
|
|
|
436
449
|
|
|
437
450
|
// Define an action provider that uses a wallet provider.
|
|
438
451
|
class MyActionProvider extends ActionProvider<WalletProvider> {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
452
|
+
constructor() {
|
|
453
|
+
super("my-action-provider", []);
|
|
454
|
+
}
|
|
442
455
|
|
|
443
|
-
|
|
444
|
-
|
|
456
|
+
// Define if the action provider supports the given network
|
|
457
|
+
supportsNetwork = (network: Network) => true;
|
|
445
458
|
}
|
|
446
459
|
```
|
|
447
460
|
|
|
@@ -455,11 +468,11 @@ Creating actions with the `@CreateAction` decorator requires the following compi
|
|
|
455
468
|
|
|
456
469
|
```json
|
|
457
470
|
{
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
}
|
|
471
|
+
"compilerOptions": {
|
|
472
|
+
"experimentalDecorators": true,
|
|
473
|
+
"emitDecoratorMetadata": true
|
|
474
|
+
}
|
|
475
|
+
}
|
|
463
476
|
```
|
|
464
477
|
|
|
465
478
|
#### Steps to create an action
|
|
@@ -480,20 +493,20 @@ export const MyActionSchema = z.object({
|
|
|
480
493
|
import { ActionProvider, WalletProvider, Network, CreateAction } from "@coinbase/agentkit";
|
|
481
494
|
|
|
482
495
|
class MyActionProvider extends ActionProvider<WalletProvider> {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
496
|
+
constructor() {
|
|
497
|
+
super("my-action-provider", []);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
@CreateAction({
|
|
501
|
+
name: "my-action",
|
|
502
|
+
description: "My action description",
|
|
503
|
+
schema: MyActionSchema,
|
|
504
|
+
})
|
|
505
|
+
async myAction(args: z.infer<typeof MyActionSchema>): Promise<string> {
|
|
506
|
+
return args.myField;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
supportsNetwork = (network: Network) => true;
|
|
497
510
|
}
|
|
498
511
|
|
|
499
512
|
export const myActionProvider = () => new MyActionProvider();
|
|
@@ -505,31 +518,34 @@ Actions that use a wallet provider can be defined as instance methods on the act
|
|
|
505
518
|
|
|
506
519
|
```typescript
|
|
507
520
|
class MyActionProvider extends ActionProvider<WalletProvider> {
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
521
|
+
constructor() {
|
|
522
|
+
super("my-action-provider", []);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
@CreateAction({
|
|
526
|
+
name: "my-action",
|
|
527
|
+
description: "My action description",
|
|
528
|
+
schema: MyActionSchema,
|
|
529
|
+
})
|
|
530
|
+
async myAction(
|
|
531
|
+
walletProvider: WalletProvider,
|
|
532
|
+
args: z.infer<typeof MyActionSchema>,
|
|
533
|
+
): Promise<string> {
|
|
534
|
+
return walletProvider.signMessage(args.myField);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
supportsNetwork = (network: Network) => true;
|
|
522
538
|
}
|
|
523
539
|
```
|
|
524
540
|
|
|
525
|
-
### Adding an Action Provider to your AgentKit instance.
|
|
541
|
+
### Adding an Action Provider to your AgentKit instance.
|
|
526
542
|
|
|
527
543
|
This gives your agent access to the actions defined in the action provider.
|
|
528
544
|
|
|
529
545
|
```typescript
|
|
530
546
|
const agentKit = new AgentKit({
|
|
531
547
|
cdpApiKeyId: "CDP API KEY NAME",
|
|
532
|
-
|
|
548
|
+
cdpApiKeySecret: "CDP API KEY SECRET",
|
|
533
549
|
actionProviders: [myActionProvider()],
|
|
534
550
|
});
|
|
535
551
|
```
|
|
@@ -539,26 +555,27 @@ const agentKit = new AgentKit({
|
|
|
539
555
|
Wallet providers give an agent access to a wallet. AgentKit currently supports the following wallet providers:
|
|
540
556
|
|
|
541
557
|
EVM:
|
|
542
|
-
|
|
543
|
-
- [
|
|
558
|
+
|
|
559
|
+
- [CdpEvmWalletProvider](https://github.com/coinbase/agentkit/blob/main/typescript/agentkit/src/wallet-providers/cdpEvmWalletProvider.ts)
|
|
560
|
+
- [CdpSmartWalletProvider](https://github.com/coinbase/agentkit/blob/main/typescript/agentkit/src/wallet-providers/cdpSmartWalletProvider.ts)
|
|
544
561
|
- [ViemWalletProvider](https://github.com/coinbase/agentkit/blob/main/typescript/agentkit/src/wallet-providers/viemWalletProvider.ts)
|
|
545
562
|
- [PrivyWalletProvider](https://github.com/coinbase/agentkit/blob/main/typescript/agentkit/src/wallet-providers/privyWalletProvider.ts)
|
|
546
563
|
- [ZeroDevWalletProvider](https://github.com/coinbase/agentkit/blob/main/typescript/agentkit/src/wallet-providers/zeroDevWalletProvider.ts)
|
|
547
564
|
|
|
548
|
-
###
|
|
565
|
+
### CdpEvmWalletProvider
|
|
549
566
|
|
|
550
|
-
The `
|
|
567
|
+
The `CdpEvmWalletProvider` is a wallet provider that uses the Coinbase Developer Platform (CDP) [v2 Wallet API](https://docs.cdp.coinbase.com/wallet-api/v2/introduction/welcome). It provides a more modern and streamlined interface for interacting with CDP wallets.
|
|
551
568
|
|
|
552
569
|
#### Basic Configuration
|
|
553
570
|
|
|
554
571
|
```typescript
|
|
555
|
-
import {
|
|
572
|
+
import { CdpEvmWalletProvider } from "@coinbase/agentkit";
|
|
556
573
|
|
|
557
|
-
const walletProvider = await
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
574
|
+
const walletProvider = await CdpEvmWalletProvider.configureWithWallet({
|
|
575
|
+
apiKeyId: "CDP_API_KEY_ID",
|
|
576
|
+
apiKeySecret: "CDP_API_KEY_SECRET",
|
|
577
|
+
walletSecret: "CDP_WALLET_SECRET",
|
|
578
|
+
networkId: "base-sepolia", // Optional, defaults to "base-sepolia"
|
|
562
579
|
});
|
|
563
580
|
```
|
|
564
581
|
|
|
@@ -567,14 +584,14 @@ const walletProvider = await CdpV2EvmWalletProvider.configureWithWallet({
|
|
|
567
584
|
You can configure the provider with an existing wallet by providing the wallet's address:
|
|
568
585
|
|
|
569
586
|
```typescript
|
|
570
|
-
import {
|
|
571
|
-
|
|
572
|
-
const walletProvider = await
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
587
|
+
import { CdpEvmWalletProvider } from "@coinbase/agentkit";
|
|
588
|
+
|
|
589
|
+
const walletProvider = await CdpEvmWalletProvider.configureWithWallet({
|
|
590
|
+
apiKeyId: "CDP_API_KEY_ID",
|
|
591
|
+
apiKeySecret: "CDP_API_KEY_SECRET",
|
|
592
|
+
walletSecret: "CDP_WALLET_SECRET",
|
|
593
|
+
address: "0x...", // The address of an existing wallet
|
|
594
|
+
networkId: "base-sepolia",
|
|
578
595
|
});
|
|
579
596
|
```
|
|
580
597
|
|
|
@@ -583,14 +600,124 @@ const walletProvider = await CdpV2EvmWalletProvider.configureWithWallet({
|
|
|
583
600
|
To create a new wallet, you can provide an idempotency key. The same idempotency key will always generate the same wallet address, and these keys are valid for 24 hours:
|
|
584
601
|
|
|
585
602
|
```typescript
|
|
586
|
-
import {
|
|
587
|
-
|
|
588
|
-
const walletProvider = await
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
603
|
+
import { CdpEvmWalletProvider } from "@coinbase/agentkit";
|
|
604
|
+
|
|
605
|
+
const walletProvider = await CdpEvmWalletProvider.configureWithWallet({
|
|
606
|
+
apiKeyId: "CDP_API_KEY_ID",
|
|
607
|
+
apiKeySecret: "CDP_API_KEY_SECRET",
|
|
608
|
+
walletSecret: "CDP_WALLET_SECRET",
|
|
609
|
+
idempotencyKey: "unique-key-123", // Optional, if not provided a new wallet will be created
|
|
610
|
+
networkId: "base-sepolia",
|
|
611
|
+
});
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
#### Environment Variables
|
|
615
|
+
|
|
616
|
+
The provider can also be configured using environment variables:
|
|
617
|
+
|
|
618
|
+
```typescript
|
|
619
|
+
// Environment variables:
|
|
620
|
+
// CDP_API_KEY_ID=your_api_key_id
|
|
621
|
+
// CDP_API_KEY_SECRET=your_api_key_secret
|
|
622
|
+
// CDP_WALLET_SECRET=your_wallet_secret
|
|
623
|
+
// NETWORK_ID=base-sepolia (optional)
|
|
624
|
+
// IDEMPOTENCY_KEY=unique-key-123 (optional)
|
|
625
|
+
|
|
626
|
+
const walletProvider = await CdpEvmWalletProvider.configureWithWallet();
|
|
627
|
+
```
|
|
628
|
+
|
|
629
|
+
#### Exporting a wallet
|
|
630
|
+
|
|
631
|
+
The `CdpEvmWalletProvider` can export a wallet by calling the `exportWallet` method:
|
|
632
|
+
|
|
633
|
+
```typescript
|
|
634
|
+
const walletData = await walletProvider.exportWallet();
|
|
635
|
+
```
|
|
636
|
+
|
|
637
|
+
### CdpSmartWalletProvider
|
|
638
|
+
|
|
639
|
+
The `CdpSmartWalletProvider` is a wallet provider that uses the Coinbase Developer Platform (CDP) [Smart Wallets](https://docs.cdp.coinbase.com/wallet-api/docs/smart-wallets). Smart wallets are ERC-4337 compliant smart contract wallets that provide enhanced features like gasless transactions, batch operations, and account recovery.
|
|
640
|
+
|
|
641
|
+
**Note:** Smart wallets are currently only supported on Base networks (base-sepolia and base-mainnet).
|
|
642
|
+
|
|
643
|
+
#### Basic Configuration
|
|
644
|
+
|
|
645
|
+
```typescript
|
|
646
|
+
import { CdpSmartWalletProvider } from "@coinbase/agentkit";
|
|
647
|
+
|
|
648
|
+
const walletProvider = await CdpSmartWalletProvider.configureWithWallet({
|
|
649
|
+
apiKeyId: "CDP_API_KEY_ID",
|
|
650
|
+
apiKeySecret: "CDP_API_KEY_SECRET",
|
|
651
|
+
walletSecret: "CDP_WALLET_SECRET",
|
|
652
|
+
networkId: "base-sepolia", // Optional, defaults to "base-sepolia"
|
|
653
|
+
});
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
#### Using an Existing Smart Wallet
|
|
657
|
+
|
|
658
|
+
You can configure the provider with an existing smart wallet by providing either the wallet's address or name:
|
|
659
|
+
|
|
660
|
+
```typescript
|
|
661
|
+
import { CdpSmartWalletProvider } from "@coinbase/agentkit";
|
|
662
|
+
|
|
663
|
+
// Using smart wallet address
|
|
664
|
+
const walletProvider = await CdpSmartWalletProvider.configureWithWallet({
|
|
665
|
+
apiKeyId: "CDP_API_KEY_ID",
|
|
666
|
+
apiKeySecret: "CDP_API_KEY_SECRET",
|
|
667
|
+
walletSecret: "CDP_WALLET_SECRET",
|
|
668
|
+
address: "0x...", // The address of an existing smart wallet
|
|
669
|
+
networkId: "base-sepolia",
|
|
670
|
+
});
|
|
671
|
+
|
|
672
|
+
// Or using smart wallet name
|
|
673
|
+
const walletProvider = await CdpSmartWalletProvider.configureWithWallet({
|
|
674
|
+
apiKeyId: "CDP_API_KEY_ID",
|
|
675
|
+
apiKeySecret: "CDP_API_KEY_SECRET",
|
|
676
|
+
walletSecret: "CDP_WALLET_SECRET",
|
|
677
|
+
smartAccountName: "my-smart-wallet", // The name of an existing smart wallet
|
|
678
|
+
networkId: "base-sepolia",
|
|
679
|
+
});
|
|
680
|
+
```
|
|
681
|
+
|
|
682
|
+
#### Specifying an Owner Account
|
|
683
|
+
|
|
684
|
+
Smart wallets require an owner account. You can specify an existing owner account by providing its address or the account object itself:
|
|
685
|
+
|
|
686
|
+
```typescript
|
|
687
|
+
import { CdpSmartWalletProvider } from "@coinbase/agentkit";
|
|
688
|
+
|
|
689
|
+
// Using owner address
|
|
690
|
+
const walletProvider = await CdpSmartWalletProvider.configureWithWallet({
|
|
691
|
+
apiKeyId: "CDP_API_KEY_ID",
|
|
692
|
+
apiKeySecret: "CDP_API_KEY_SECRET",
|
|
693
|
+
walletSecret: "CDP_WALLET_SECRET",
|
|
694
|
+
owner: "0x...", // The address of the owner account
|
|
695
|
+
networkId: "base-sepolia",
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
// Using owner account object
|
|
699
|
+
const walletProvider = await CdpSmartWalletProvider.configureWithWallet({
|
|
700
|
+
apiKeyId: "CDP_API_KEY_ID",
|
|
701
|
+
apiKeySecret: "CDP_API_KEY_SECRET",
|
|
702
|
+
walletSecret: "CDP_WALLET_SECRET",
|
|
703
|
+
owner: ownerAccount, // An EvmServerAccount or PrivateKeyAccount object
|
|
704
|
+
networkId: "base-sepolia",
|
|
705
|
+
});
|
|
706
|
+
```
|
|
707
|
+
|
|
708
|
+
#### Creating a New Smart Wallet
|
|
709
|
+
|
|
710
|
+
To create a new smart wallet, provide an idempotency key. The same idempotency key will always generate the same owner account address, and these keys are valid for 24 hours:
|
|
711
|
+
|
|
712
|
+
```typescript
|
|
713
|
+
import { CdpSmartWalletProvider } from "@coinbase/agentkit";
|
|
714
|
+
|
|
715
|
+
const walletProvider = await CdpSmartWalletProvider.configureWithWallet({
|
|
716
|
+
apiKeyId: "CDP_API_KEY_ID",
|
|
717
|
+
apiKeySecret: "CDP_API_KEY_SECRET",
|
|
718
|
+
walletSecret: "CDP_WALLET_SECRET",
|
|
719
|
+
idempotencyKey: "unique-key-123", // Optional, if not provided a new owner account will be created
|
|
720
|
+
networkId: "base-sepolia",
|
|
594
721
|
});
|
|
595
722
|
```
|
|
596
723
|
|
|
@@ -606,64 +733,87 @@ The provider can also be configured using environment variables:
|
|
|
606
733
|
// NETWORK_ID=base-sepolia (optional)
|
|
607
734
|
// IDEMPOTENCY_KEY=unique-key-123 (optional)
|
|
608
735
|
|
|
609
|
-
const walletProvider = await
|
|
736
|
+
const walletProvider = await CdpSmartWalletProvider.configureWithWallet();
|
|
737
|
+
```
|
|
738
|
+
|
|
739
|
+
#### Exporting Smart Wallet Information
|
|
740
|
+
|
|
741
|
+
The `CdpSmartWalletProvider` can export wallet information by calling the `exportWallet` method:
|
|
742
|
+
|
|
743
|
+
```typescript
|
|
744
|
+
const walletData = await walletProvider.exportWallet();
|
|
745
|
+
|
|
746
|
+
// walletData will be in the following format:
|
|
747
|
+
{
|
|
748
|
+
name: string | undefined; // The smart wallet name (if set)
|
|
749
|
+
address: string; // The smart wallet address
|
|
750
|
+
ownerAddress: string; // The owner account address
|
|
751
|
+
}
|
|
610
752
|
```
|
|
611
753
|
|
|
612
|
-
|
|
754
|
+
#### Key Differences from Regular Wallets
|
|
755
|
+
|
|
756
|
+
1. **User Operations**: Smart wallets use ERC-4337 user operations instead of regular transactions
|
|
757
|
+
2. **No Direct Transaction Signing**: Smart wallets cannot sign transactions directly; all operations go through the user operation flow
|
|
758
|
+
3. **Gasless Transactions**: Smart wallets can be configured to use paymasters for sponsored transactions
|
|
759
|
+
4. **Batch Operations**: Multiple operations can be bundled into a single user operation
|
|
760
|
+
5. **Base Networks Only**: Currently limited to base-sepolia and base-mainnet
|
|
613
761
|
|
|
614
|
-
|
|
762
|
+
### LegacyCdpWalletProvider
|
|
763
|
+
|
|
764
|
+
The `LegacyCdpWalletProvider` is a wallet provider that uses the Coinbase Developer Platform (CDP) [v1 Wallet API](https://docs.cdp.coinbase.com/wallet-api/v1/introduction/welcome).
|
|
615
765
|
|
|
616
766
|
#### Network Configuration
|
|
617
767
|
|
|
618
|
-
The `
|
|
768
|
+
The `LegacyCdpWalletProvider` can be configured to use a specific network by passing the `networkId` parameter to the `configureWithWallet` method. The `networkId` is the ID of the network you want to use. You can find a list of [supported networks on the CDP API docs](https://docs.cdp.coinbase.com/cdp-apis/docs/networks).
|
|
619
769
|
|
|
620
770
|
```typescript
|
|
621
|
-
import {
|
|
771
|
+
import { LegacyCdpWalletProvider } from "@coinbase/agentkit";
|
|
622
772
|
|
|
623
773
|
const walletProvider = await CdpWalletProvider.configureWithWallet({
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
774
|
+
apiKeyId: "CDP API KEY NAME",
|
|
775
|
+
apiKeyPrivate: "CDP API KEY SECRET",
|
|
776
|
+
networkId: "base-mainnet",
|
|
627
777
|
});
|
|
628
778
|
```
|
|
629
779
|
|
|
630
780
|
#### Configuring from an existing CDP API Wallet
|
|
631
781
|
|
|
632
|
-
If you already have a CDP API Wallet, you can configure the `
|
|
782
|
+
If you already have a CDP API Wallet, you can configure the `LegacyCdpWalletProvider` by passing the `wallet` parameter to the `configureWithWallet` method.
|
|
633
783
|
|
|
634
784
|
```typescript
|
|
635
|
-
import {
|
|
785
|
+
import { LegacyCdpWalletProvider } from "@coinbase/agentkit";
|
|
636
786
|
import { Wallet } from "@coinbase/coinbase-sdk";
|
|
637
|
-
const walletProvider = await
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
787
|
+
const walletProvider = await LegacyCdpWalletProvider.configureWithWallet({
|
|
788
|
+
wallet,
|
|
789
|
+
apiKeyId: "CDP API KEY NAME",
|
|
790
|
+
apiKeyPrivate: "CDP API KEY SECRET",
|
|
641
791
|
});
|
|
642
792
|
```
|
|
643
793
|
|
|
644
794
|
#### Configuring from a mnemonic phrase
|
|
645
795
|
|
|
646
|
-
The `
|
|
796
|
+
The `LegacyCdpWalletProvider` can be configured from a mnemonic phrase by passing the `mnemonicPhrase` and `networkId` parameters to the `configureWithWallet` method. If `networkId` is not defined, the `LegacyCdpWalletProvider` will fall back to the env var `NETWORK_ID`, and if that is not defined, it will default to `base-sepolia`.
|
|
647
797
|
|
|
648
798
|
```typescript
|
|
649
|
-
import {
|
|
799
|
+
import { LegacyCdpWalletProvider } from "@coinbase/agentkit";
|
|
650
800
|
|
|
651
|
-
const walletProvider = await
|
|
652
|
-
|
|
653
|
-
|
|
801
|
+
const walletProvider = await LegacyCdpWalletProvider.configureWithWallet({
|
|
802
|
+
mnemonicPhrase: "MNEMONIC PHRASE",
|
|
803
|
+
networkId: "base-sepolia",
|
|
654
804
|
});
|
|
655
805
|
```
|
|
656
806
|
|
|
657
807
|
#### Exporting a wallet
|
|
658
808
|
|
|
659
|
-
The `
|
|
809
|
+
The `LegacyCdpWalletProvider` can export a wallet by calling the `exportWallet` method.
|
|
660
810
|
|
|
661
811
|
```typescript
|
|
662
|
-
import {
|
|
812
|
+
import { LegacyCdpWalletProvider } from "@coinbase/agentkit";
|
|
663
813
|
|
|
664
|
-
const walletProvider = await
|
|
665
|
-
|
|
666
|
-
|
|
814
|
+
const walletProvider = await LegacyCdpWalletProvider.configureWithWallet({
|
|
815
|
+
mnemonicPhrase: "MNEMONIC PHRASE",
|
|
816
|
+
networkId: "base-sepolia",
|
|
667
817
|
});
|
|
668
818
|
|
|
669
819
|
const walletData = await walletProvider.exportWallet();
|
|
@@ -671,39 +821,38 @@ const walletData = await walletProvider.exportWallet();
|
|
|
671
821
|
|
|
672
822
|
#### Importing a wallet from `WalletData` JSON string
|
|
673
823
|
|
|
674
|
-
The `
|
|
824
|
+
The `LegacyCdpWalletProvider` can import a wallet from a `WalletData` JSON string by passing the `cdpWalletData` parameter to the `configureWithWallet` method.
|
|
675
825
|
|
|
676
826
|
```typescript
|
|
677
|
-
import {
|
|
827
|
+
import { LegacyCdpWalletProvider } from "@coinbase/agentkit";
|
|
678
828
|
|
|
679
|
-
const walletProvider = await
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
829
|
+
const walletProvider = await LegacyCdpWalletProvider.configureWithWallet({
|
|
830
|
+
cdpWalletData: "WALLET DATA JSON STRING",
|
|
831
|
+
apiKeyId: "CDP API KEY NAME",
|
|
832
|
+
apiKeyPrivate: "CDP API KEY SECRET",
|
|
683
833
|
});
|
|
684
834
|
```
|
|
685
835
|
|
|
686
|
-
#### Configuring
|
|
836
|
+
#### Configuring LegacyCdpWalletProvider gas parameters
|
|
687
837
|
|
|
688
|
-
The `
|
|
838
|
+
The `LegacyCdpWalletProvider` also exposes parameters for effecting the gas calculations.
|
|
689
839
|
|
|
690
840
|
```typescript
|
|
691
|
-
import {
|
|
692
|
-
|
|
693
|
-
const walletProvider = await
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
841
|
+
import { LegacyCdpWalletProvider } from "@coinbase/agentkit";
|
|
842
|
+
|
|
843
|
+
const walletProvider = await LegacyCdpWalletProvider.configureWithWallet({
|
|
844
|
+
cdpWalletData: "WALLET DATA JSON STRING",
|
|
845
|
+
apiKeyId: "CDP API KEY NAME",
|
|
846
|
+
apiKeyPrivate: "CDP API KEY SECRET",
|
|
847
|
+
gas: {
|
|
848
|
+
gasLimitMultiplier: 2.0, // Adjusts gas limit estimation
|
|
849
|
+
feePerGasMultiplier: 2.0, // Adjusts max fee per gas
|
|
850
|
+
},
|
|
701
851
|
});
|
|
702
852
|
```
|
|
703
853
|
|
|
704
854
|
**Note**: Gas parameters only impact the `walletProvider.sendTransaction` behavior. Actions that do not rely on direct transaction calls, such as `deploy_token`, `deploy_contract`, and `native_transfer`, remain unaffected.
|
|
705
855
|
|
|
706
|
-
|
|
707
856
|
### ViemWalletProvider
|
|
708
857
|
|
|
709
858
|
The `ViemWalletProvider` is a wallet provider that uses the [Viem library](https://viem.sh/docs/getting-started). It is useful for interacting with any EVM-compatible chain.
|
|
@@ -750,8 +899,8 @@ const client = createWalletClient({
|
|
|
750
899
|
});
|
|
751
900
|
|
|
752
901
|
const walletProvider = new ViemWalletProvider(client, {
|
|
753
|
-
|
|
754
|
-
|
|
902
|
+
gasLimitMultiplier: 2.0, // Adjusts gas limit estimation
|
|
903
|
+
feePerGasMultiplier: 2.0, // Adjusts max fee per gas
|
|
755
904
|
});
|
|
756
905
|
```
|
|
757
906
|
|
|
@@ -766,12 +915,12 @@ import { PrivyWalletProvider } from "@coinbase/agentkit";
|
|
|
766
915
|
|
|
767
916
|
// Configure Server Wallet Provider
|
|
768
917
|
const config = {
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
918
|
+
appId: "PRIVY_APP_ID",
|
|
919
|
+
appSecret: "PRIVY_APP_SECRET",
|
|
920
|
+
chainId: "84532", // base-sepolia
|
|
921
|
+
walletId: "PRIVY_WALLET_ID", // optional, otherwise a new wallet will be created
|
|
922
|
+
authorizationPrivateKey: "PRIVY_WALLET_AUTHORIZATION_PRIVATE_KEY", // optional, required if your account is using authorization keys
|
|
923
|
+
authorizationKeyId: "PRIVY_WALLET_AUTHORIZATION_KEY_ID", // optional, only required to create a new wallet if walletId is not provided
|
|
775
924
|
};
|
|
776
925
|
|
|
777
926
|
const walletProvider = await PrivyWalletProvider.configureWithWallet(config);
|
|
@@ -786,12 +935,12 @@ import { PrivyWalletProvider } from "@coinbase/agentkit";
|
|
|
786
935
|
|
|
787
936
|
// Configure Embedded Wallet Provider
|
|
788
937
|
const config = {
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
938
|
+
appId: "PRIVY_APP_ID",
|
|
939
|
+
appSecret: "PRIVY_APP_SECRET",
|
|
940
|
+
authorizationPrivateKey: "PRIVY_WALLET_AUTHORIZATION_PRIVATE_KEY",
|
|
941
|
+
walletId: "PRIVY_DELEGATED_WALLET_ID", // The ID of the wallet that was delegated to your server
|
|
942
|
+
networkId: "base-mainnet", // or any supported network
|
|
943
|
+
walletType: "embedded", // Specify "embedded" to use the embedded wallet provider
|
|
795
944
|
};
|
|
796
945
|
|
|
797
946
|
const walletProvider = await PrivyWalletProvider.configureWithWallet(config);
|
|
@@ -822,23 +971,23 @@ When using authorization keys, you must provide the `authorizationPrivateKey` an
|
|
|
822
971
|
|
|
823
972
|
#### Exporting Privy Wallet information
|
|
824
973
|
|
|
825
|
-
The `PrivyWalletProvider` can export wallet information by calling the `exportWallet` method.
|
|
974
|
+
The `PrivyWalletProvider` can export wallet information by calling the `exportWallet` method.
|
|
826
975
|
|
|
827
976
|
```typescript
|
|
828
977
|
const walletData = await walletProvider.exportWallet();
|
|
829
978
|
|
|
830
979
|
// For server wallets, walletData will be in the following format:
|
|
831
980
|
{
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
981
|
+
walletId: string;
|
|
982
|
+
authorizationKey: string | undefined;
|
|
983
|
+
chainId: string | undefined;
|
|
835
984
|
}
|
|
836
985
|
|
|
837
986
|
// For embedded wallets, walletData will be in the following format:
|
|
838
987
|
{
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
988
|
+
walletId: string;
|
|
989
|
+
networkId: string;
|
|
990
|
+
chainId: string | undefined;
|
|
842
991
|
}
|
|
843
992
|
```
|
|
844
993
|
|
|
@@ -866,11 +1015,11 @@ const walletProvider = await SmartWalletProvider.configureWithWallet({
|
|
|
866
1015
|
|
|
867
1016
|
### ZeroDevWalletProvider
|
|
868
1017
|
|
|
869
|
-
The `ZeroDevWalletProvider` is a wallet provider that uses [ZeroDev](https://docs.zerodev.app/) smart accounts.
|
|
1018
|
+
The `ZeroDevWalletProvider` is a wallet provider that uses [ZeroDev](https://docs.zerodev.app/) smart accounts. It supports features like chain abstraction, gasless transactions, batched transactions, and more.
|
|
870
1019
|
|
|
871
|
-
In the context of Agent Kit, "chain abstraction" means that the agent can spend funds across chains without explicitly bridging.
|
|
1020
|
+
In the context of Agent Kit, "chain abstraction" means that the agent can spend funds across chains without explicitly bridging. For example, if you send funds to the agent's address on Base, the agent will be able to spend the funds on any supported EVM chains such as Arbitrum and Optimism.
|
|
872
1021
|
|
|
873
|
-
The ZeroDev wallet provider does not itself manage keys.
|
|
1022
|
+
The ZeroDev wallet provider does not itself manage keys. Rather, it can be used with any EVM wallet provider (e.g. CDP/Privy/Viem) which serves as the "signer" for the ZeroDev smart account.
|
|
874
1023
|
|
|
875
1024
|
#### Configuring from CdpWalletProvider
|
|
876
1025
|
|
|
@@ -879,17 +1028,17 @@ import { ZeroDevWalletProvider, CdpWalletProvider } from "@coinbase/agentkit";
|
|
|
879
1028
|
|
|
880
1029
|
// First create a CDP wallet provider as the signer
|
|
881
1030
|
const cdpWalletProvider = await CdpWalletProvider.configureWithWallet({
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
1031
|
+
apiKeyId: "CDP API KEY NAME",
|
|
1032
|
+
apiKeyPrivate: "CDP API KEY SECRET",
|
|
1033
|
+
networkId: "base-mainnet",
|
|
885
1034
|
});
|
|
886
1035
|
|
|
887
1036
|
// Configure ZeroDev Wallet Provider with CDP signer
|
|
888
1037
|
const walletProvider = await ZeroDevWalletProvider.configureWithWallet({
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
1038
|
+
signer: cdpWalletProvider.toSigner(),
|
|
1039
|
+
projectId: "ZERODEV_PROJECT_ID",
|
|
1040
|
+
entryPointVersion: "0.7" as const,
|
|
1041
|
+
networkId: "base-mainnet",
|
|
893
1042
|
});
|
|
894
1043
|
```
|
|
895
1044
|
|
|
@@ -900,17 +1049,17 @@ import { ZeroDevWalletProvider, PrivyWalletProvider } from "@coinbase/agentkit";
|
|
|
900
1049
|
|
|
901
1050
|
// First create a Privy wallet provider as the signer
|
|
902
1051
|
const privyWalletProvider = await PrivyWalletProvider.configureWithWallet({
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
1052
|
+
appId: "PRIVY_APP_ID",
|
|
1053
|
+
appSecret: "PRIVY_APP_SECRET",
|
|
1054
|
+
chainId: "8453", // base-mainnet
|
|
906
1055
|
});
|
|
907
1056
|
|
|
908
1057
|
// Configure ZeroDev Wallet Provider with Privy signer
|
|
909
1058
|
const walletProvider = await ZeroDevWalletProvider.configureWithWallet({
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
1059
|
+
signer: privyWalletProvider.toSigner(),
|
|
1060
|
+
projectId: "ZERODEV_PROJECT_ID",
|
|
1061
|
+
entryPointVersion: "0.7" as const,
|
|
1062
|
+
networkId: "base-mainnet",
|
|
914
1063
|
});
|
|
915
1064
|
```
|
|
916
1065
|
|
|
@@ -930,15 +1079,15 @@ const viemWalletProvider = new ViemWalletProvider(
|
|
|
930
1079
|
account,
|
|
931
1080
|
chain: base,
|
|
932
1081
|
transport: http(),
|
|
933
|
-
})
|
|
1082
|
+
}),
|
|
934
1083
|
);
|
|
935
1084
|
|
|
936
1085
|
// Configure ZeroDev Wallet Provider with Viem signer
|
|
937
1086
|
const walletProvider = await ZeroDevWalletProvider.configureWithWallet({
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
1087
|
+
signer: viemWalletProvider.toSigner(),
|
|
1088
|
+
projectId: "ZERODEV_PROJECT_ID",
|
|
1089
|
+
entryPointVersion: "0.7" as const,
|
|
1090
|
+
networkId: "base-mainnet",
|
|
942
1091
|
});
|
|
943
1092
|
```
|
|
944
1093
|
|
|
@@ -947,6 +1096,7 @@ const walletProvider = await ZeroDevWalletProvider.configureWithWallet({
|
|
|
947
1096
|
Wallet providers give an agent access to a wallet. AgentKit currently supports the following wallet providers:
|
|
948
1097
|
|
|
949
1098
|
SVM:
|
|
1099
|
+
|
|
950
1100
|
- [CdpV2SolanaWalletProvider](https://github.com/coinbase/agentkit/blob/main/typescript/agentkit/src/wallet-providers/cdpV2SolanaWalletProvider.ts)
|
|
951
1101
|
- [SolanaKeypairWalletProvider](https://github.com/coinbase/agentkit/blob/main/typescript/agentkit/src/wallet-providers/solanaKeypairWalletProvider.ts)
|
|
952
1102
|
- [PrivyWalletProvider](https://github.com/coinbase/agentkit/blob/main/typescript/agentkit/src/wallet-providers/privySvmWalletProvider.ts)
|
|
@@ -961,10 +1111,10 @@ The `CdpV2SolanaWalletProvider` is a wallet provider that uses the Coinbase Deve
|
|
|
961
1111
|
import { CdpV2SolanaWalletProvider } from "@coinbase/agentkit";
|
|
962
1112
|
|
|
963
1113
|
const walletProvider = await CdpV2SolanaWalletProvider.configureWithWallet({
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
1114
|
+
apiKeyId: "CDP_API_KEY_ID",
|
|
1115
|
+
apiKeySecret: "CDP_API_KEY_SECRET",
|
|
1116
|
+
walletSecret: "CDP_WALLET_SECRET",
|
|
1117
|
+
networkId: "solana-devnet", // Optional, defaults to "solana-devnet"
|
|
968
1118
|
});
|
|
969
1119
|
```
|
|
970
1120
|
|
|
@@ -976,11 +1126,11 @@ You can configure the provider with an existing wallet by providing the wallet's
|
|
|
976
1126
|
import { CdpV2SolanaWalletProvider } from "@coinbase/agentkit";
|
|
977
1127
|
|
|
978
1128
|
const walletProvider = await CdpV2SolanaWalletProvider.configureWithWallet({
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
1129
|
+
apiKeyId: "CDP_API_KEY_ID",
|
|
1130
|
+
apiKeySecret: "CDP_API_KEY_SECRET",
|
|
1131
|
+
walletSecret: "CDP_WALLET_SECRET",
|
|
1132
|
+
address: "your-solana-address", // The address of an existing wallet
|
|
1133
|
+
networkId: "solana-devnet",
|
|
984
1134
|
});
|
|
985
1135
|
```
|
|
986
1136
|
|
|
@@ -992,11 +1142,11 @@ To create a new wallet, you can provide an idempotency key. The same idempotency
|
|
|
992
1142
|
import { CdpV2SolanaWalletProvider } from "@coinbase/agentkit";
|
|
993
1143
|
|
|
994
1144
|
const walletProvider = await CdpV2SolanaWalletProvider.configureWithWallet({
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1145
|
+
apiKeyId: "CDP_API_KEY_ID",
|
|
1146
|
+
apiKeySecret: "CDP_API_KEY_SECRET",
|
|
1147
|
+
walletSecret: "CDP_WALLET_SECRET",
|
|
1148
|
+
idempotencyKey: "unique-key-123", // Optional, if not provided a new wallet will be created
|
|
1149
|
+
networkId: "solana-devnet",
|
|
1000
1150
|
});
|
|
1001
1151
|
```
|
|
1002
1152
|
|
|
@@ -1018,13 +1168,14 @@ const walletProvider = await CdpV2SolanaWalletProvider.configureWithWallet();
|
|
|
1018
1168
|
#### Supported Networks
|
|
1019
1169
|
|
|
1020
1170
|
The `CdpV2SolanaWalletProvider` supports the following Solana networks:
|
|
1171
|
+
|
|
1021
1172
|
- `solana-mainnet`
|
|
1022
1173
|
- `solana-devnet`
|
|
1023
1174
|
- `solana-testnet`
|
|
1024
1175
|
|
|
1025
1176
|
### SolanaKeypairWalletProvider
|
|
1026
1177
|
|
|
1027
|
-
The `SolanaKeypairWalletProvider` is a wallet provider that uses the API [Solana web3.js](https://solana
|
|
1178
|
+
The `SolanaKeypairWalletProvider` is a wallet provider that uses the API [Solana web3.js](https://solana.com/docs/clients/javascript).
|
|
1028
1179
|
|
|
1029
1180
|
NOTE: It is highly recommended to use a dedicated RPC provider. See [here](https://solana.com/rpc) for more info on Solana RPC infrastructure, and see [here](#rpc-url-configuration) for instructions on configuring `SolanaKeypairWalletProvider` with a custom RPC URL.
|
|
1030
1181
|
|
|
@@ -1033,6 +1184,7 @@ NOTE: It is highly recommended to use a dedicated RPC provider. See [here](https
|
|
|
1033
1184
|
The `SolanaKeypairWalletProvider` can be configured to use a specific network by passing the `networkId` parameter to the `fromNetwork` method. The `networkId` is the ID of the Solana network you want to use. Valid values are `solana-mainnet`, `solana-devnet` and `solana-testnet`.
|
|
1034
1185
|
|
|
1035
1186
|
The default RPC endpoints for each network are as follows:
|
|
1187
|
+
|
|
1036
1188
|
- `solana-mainnet`: `https://api.mainnet-beta.solana.com`
|
|
1037
1189
|
- `solana-devnet`: `https://api.devnet.solana.com`
|
|
1038
1190
|
- `solana-testnet`: `https://api.testnet.solana.com`
|
|
@@ -1070,14 +1222,14 @@ import { PrivyWalletProvider, PrivyWalletConfig } from "@coinbase/agentkit";
|
|
|
1070
1222
|
|
|
1071
1223
|
// Configure Wallet Provider
|
|
1072
1224
|
const config: PrivyWalletConfig = {
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1225
|
+
appId: "PRIVY_APP_ID",
|
|
1226
|
+
appSecret: "PRIVY_APP_SECRET",
|
|
1227
|
+
connection,
|
|
1228
|
+
chainType: "solana", // optional, defaults to "evm". Make sure to set this to "solana" if you want to use Solana!
|
|
1229
|
+
networkId: "solana-devnet", // optional, defaults to "solana-devnet"
|
|
1230
|
+
walletId: "PRIVY_WALLET_ID", // optional, otherwise a new wallet will be created
|
|
1231
|
+
authorizationPrivateKey: PRIVY_WALLET_AUTHORIZATION_PRIVATE_KEY, // optional, required if your account is using authorization keys
|
|
1232
|
+
authorizationKeyId: PRIVY_WALLET_AUTHORIZATION_KEY_ID, // optional, only required to create a new wallet if walletId is not provided
|
|
1081
1233
|
};
|
|
1082
1234
|
|
|
1083
1235
|
const walletProvider = await PrivyWalletProvider.configureWithWallet(config);
|
|
@@ -1094,14 +1246,14 @@ const connection = new Connection("YOUR_RPC_URL");
|
|
|
1094
1246
|
|
|
1095
1247
|
// Configure Wallet Provider
|
|
1096
1248
|
const config: PrivyWalletConfig = {
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1249
|
+
appId: "PRIVY_APP_ID",
|
|
1250
|
+
appSecret: "PRIVY_APP_SECRET",
|
|
1251
|
+
connection,
|
|
1252
|
+
chainType: "solana", // optional, defaults to "evm". Make sure to set this to "solana" if you want to use Solana!
|
|
1253
|
+
networkId: "solana-devnet", // optional, defaults to "solana-devnet"
|
|
1254
|
+
walletId: "PRIVY_WALLET_ID", // optional, otherwise a new wallet will be created
|
|
1255
|
+
authorizationPrivateKey: PRIVY_WALLET_AUTHORIZATION_PRIVATE_KEY, // optional, required if your account is using authorization keys
|
|
1256
|
+
authorizationKeyId: PRIVY_WALLET_AUTHORIZATION_KEY_ID, // optional, only required to create a new wallet if walletId is not provided
|
|
1105
1257
|
};
|
|
1106
1258
|
|
|
1107
1259
|
const walletProvider = await PrivyWalletProvider.configureWithWallet(config);
|
|
@@ -1124,9 +1276,9 @@ const walletData = await walletProvider.exportWallet();
|
|
|
1124
1276
|
|
|
1125
1277
|
// walletData will be in the following format:
|
|
1126
1278
|
{
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1279
|
+
walletId: string;
|
|
1280
|
+
authorizationKey: string | undefined;
|
|
1281
|
+
networkId: string | undefined;
|
|
1130
1282
|
}
|
|
1131
1283
|
```
|
|
1132
1284
|
|