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: embedded-wallets/infrastructure/nodes-and-dkg.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ The architecture consists of four parts:
13
13
- A private BFT network between nodes
14
14
- A front-end client/SDK that interacts with nodes
15
15
16
-

16
+

17
17
18
18
A smart contract is used for node discovery. Nodes are selected, operate for a fixed period, and generate a set of keys via DKG.
19
19
@@ -67,7 +67,7 @@ The keys are assigned to a combination of `verifier` \(e.g., Google, Reddit, Dis
67
67
68
68
The fundamental flow for Torus sign-in is as follows:
69
69
70
-

70
+

71
71
72
72
1. Your application gets the user to sign-in via their preferred method \(OAuth / email password / passwordless / verification code\).
73
73
2. After the user gives consent/verifies his/her email, Torus SDK will receive an ID token and assign a key to the user depending on User Verifier ID from ID Token.
This tutorial walks you through creating an AI agent dapp that can display your wallet balance and initiate transactions from your wallet, on the Linea Sepolia network.
12
14
You will use a provided template, which sets up MetaMask SDK and [Vercel's AI SDK](https://sdk.vercel.ai/) with a [Next.js](https://nextjs.org/docs) and [Wagmi](https://wagmi.sh/) dapp.
13
15
@@ -24,36 +26,36 @@ You will use a provided template, which sets up MetaMask SDK and [Vercel's AI SD
24
26
25
27
### 1. Set up the project
26
28
27
-
1. Clone the [`Consensys/wallet-agent`](https://github.com/Consensys/wallet-agent/tree/main) repository:
29
+
1.Clone the [`Consensys/wallet-agent`](https://github.com/Consensys/wallet-agent/tree/main) repository:
5. In `.env.local`, add an `OPENAI_API_KEY` environment variable, replacing `<YOUR-API-KEY>` with your [OpenAI](https://platform.openai.com/docs/overview) API key.
52
-
Vercel's AI SDK will use this environment variable to authenticate your dapp with the OpenAI service.
53
+
5. In `.env.local`, add an `OPENAI_API_KEY` environment variable, replacing `<YOUR-API-KEY>` with your [OpenAI](https://platform.openai.com/docs/overview) API key.
54
+
Vercel's AI SDK will use this environment variable to authenticate your dapp with the OpenAI service.
53
55
54
-
```text title=".env.local"
55
-
OPENAI_API_KEY=<YOUR-API-KEY>
56
-
```
56
+
```text title=".env.local"
57
+
OPENAI_API_KEY=<YOUR-API-KEY>
58
+
```
57
59
58
60
### 2. Create the dapp interface
59
61
@@ -78,7 +80,7 @@ import Image from "next/image";
78
80
+ const { connect } = useConnect();
79
81
+ const { address, isConnected } = useAccount();
80
82
+ const { disconnect } = useDisconnect();
81
-
+
83
+
+
82
84
+ return (
83
85
+ <div className="mx-auto">
84
86
+ {isConnected ? (
@@ -117,7 +119,7 @@ When connected, the AI agent chat interface displays with your connected wallet
117
119
You can test the AI functionality by sending messages in the chat:
118
120
119
121
<p align="center">
120
-
<img src={require("../_assets/sdk-ai-agent.png").default} alt="SDK AI agent initial setup" class="appScreen" />
122
+
<img src={require("@site/static/img/guides/sdk-ai-agent.png").default} alt="SDK AI agent initial setup" class="appScreen" />
121
123
</p>
122
124
123
125
### 3. Create a Public Client
@@ -153,7 +155,7 @@ Use the [`getBalance`](https://viem.sh/docs/actions/public/getBalance) method of
153
155
154
156
```ts title="tools.ts"
155
157
// add-start
156
-
+ import { publicClient } from "@/wagmi.config";
158
+
+ import { publicClient } from "@/wagmi.config";
157
159
+ import { formatEther } from "viem";
158
160
// add-end
159
161
import { tool as createTool } from "ai";
@@ -196,7 +198,7 @@ export const tools = {
196
198
In the development server, test that this tool works to get your current Linea Sepolia ETH balance:
197
199
198
200
<p align="center">
199
-
<img src={require("../_assets/sdk-ai-agent-get-balance.png").default} alt="SDK AI agent get balance" class="appScreen" />
201
+
<img src={require("@site/static/img/guides/sdk-ai-agent-get-balance.png").default} alt="SDK AI agent get balance" class="appScreen" />
200
202
</p>
201
203
202
204
### 5. Create a tool to send transactions
@@ -243,18 +245,15 @@ export const tools = {
243
245
244
246
```tsx
245
247
// ...
246
-
if (toolName === "sendTransaction") {
247
-
const {
248
-
result,
249
-
}: { result: { to: string; amount: string } } =
250
-
toolInvocation;
248
+
if (toolName === 'sendTransaction') {
249
+
const { result }: { result: { to: string; amount: string } } = toolInvocation
251
250
252
251
if (isLoading) {
253
252
return (
254
253
<div key={toolCallId}>
255
254
<p>Loading...</p>
256
255
</div>
257
-
);
256
+
)
258
257
}
259
258
260
259
return (
@@ -266,17 +265,12 @@ if (toolName === "sendTransaction") {
266
265
to: result.to as `0x${string}`,
267
266
value: parseEther(result.amount),
268
267
})
269
-
}
270
-
>
268
+
}>
271
269
Send Transaction
272
270
</Button>
273
-
<p>
274
-
{hash
275
-
? `Transaction sent: ${hash}`
276
-
: "Transaction not sent"}
277
-
</p>
271
+
<p>{hash ? `Transaction sent: ${hash}` : 'Transaction not sent'}</p>
278
272
</div>
279
-
);
273
+
)
280
274
}
281
275
// ...
282
276
```
@@ -289,13 +283,13 @@ In the development server, test that this tool works to send Linea Sepolia ETH f
289
283
When you request the agent to send a transaction, it will provide a button for you to send the transaction, but it will not send it for you:
You can check the status of the transaction in the [Linea Sepolia block explorer](https://sepolia.lineascan.build/).
@@ -307,4 +301,4 @@ You can configure the AI agent to directly send the transaction using a [Viem Wa
307
301
## Resources
308
302
309
303
- View the main branch of the [`Consensys/wallet-agent`](https://github.com/Consensys/wallet-agent) template for the completed implementation of this tutorial.
310
-
- Watch the [live coding session](https://www.youtube.com/watch?v=ZVuOaKuAhBQ) on YouTube, in which the MetaMask DevRel team walks through creating a wallet AI agent from the initial template.
304
+
- Watch the [live coding session](https://www.youtube.com/watch?v=ZVuOaKuAhBQ) on YouTube, in which the MetaMask DevRel team walks through creating a wallet AI agent from the initial template.
0 commit comments