keyring-chatbot-agent 1.0.1 → 1.0.3
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 +245 -153
- package/dist/chat-widget-wc.es.js +1 -1
- package/dist/chat-widget-wc.umd.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
# Keyring Chatbot Agent SDK
|
|
2
2
|
|
|
3
|
-
An AI-powered Web3 chatbot SDK
|
|
3
|
+
An AI-powered Web3 chatbot SDK. Provides a floating chat widget with on-chain capabilities: token swaps, sending tokens/NFTs, viewing balances, and natural-language AI conversation.
|
|
4
|
+
|
|
5
|
+
---
|
|
4
6
|
|
|
5
7
|
## Features
|
|
6
8
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
9
|
+
- **Natural language AI chat** — Understands user intent, distinguishes general questions from on-chain tasks
|
|
10
|
+
- **Token swaps** — Best-price routing via deBridge, automatic ERC-20 approval when needed
|
|
11
|
+
- **Send tokens** — ERC-20 and native tokens, supports "max", "50%", "$5" amount expressions
|
|
12
|
+
- **Send NFTs** — ERC-721 and ERC-1155, resolves NFT by name or token ID from the user's wallet
|
|
13
|
+
- **View balances** — Token list with USD values
|
|
14
|
+
- **Trending tokens** — Per-chain trending data with quick-buy buttons
|
|
15
|
+
- **Wrap / Unwrap** — ETH ↔ WETH and equivalents on each chain
|
|
16
|
+
- **Approve token** — ERC-20 spending allowance
|
|
17
|
+
- **Multi-language** — English, Japanese, Chinese UI
|
|
18
|
+
- **Multi-chain** — Ethereum, Optimism, BNB Chain, Polygon, Base, Arbitrum, Avalanche, Linea
|
|
19
|
+
- **Full TypeScript** — Complete type declarations included
|
|
16
20
|
|
|
17
21
|
---
|
|
18
22
|
|
|
19
23
|
## Installation
|
|
20
24
|
|
|
21
25
|
```bash
|
|
22
|
-
npm install keyring-chatbot-agent
|
|
26
|
+
npm install keyring-chatbot-agent
|
|
23
27
|
# or
|
|
24
|
-
yarn add keyring-chatbot-agent
|
|
28
|
+
yarn add keyring-chatbot-agent
|
|
25
29
|
```
|
|
26
30
|
|
|
27
31
|
**Peer dependencies** (React 17, 18, or 19):
|
|
@@ -32,21 +36,19 @@ npm install react react-dom
|
|
|
32
36
|
|
|
33
37
|
---
|
|
34
38
|
|
|
35
|
-
##
|
|
39
|
+
## React Usage
|
|
40
|
+
|
|
41
|
+
### Basic example
|
|
36
42
|
|
|
37
43
|
```tsx
|
|
38
|
-
import { ChatWidget } from 'keyring-chatbot-agent
|
|
39
|
-
import type {
|
|
40
|
-
Transaction,
|
|
41
|
-
TransactionResult,
|
|
42
|
-
} from 'keyring-chatbot-agent-sdk-test';
|
|
44
|
+
import { ChatWidget } from 'keyring-chatbot-agent';
|
|
45
|
+
import type { Transaction, TransactionResult } from 'keyring-chatbot-agent';
|
|
43
46
|
|
|
44
47
|
function App() {
|
|
45
48
|
const handleTransaction = async (
|
|
46
49
|
tx: Transaction
|
|
47
50
|
): Promise<TransactionResult> => {
|
|
48
51
|
try {
|
|
49
|
-
// Sign and send via your wallet provider (wagmi, ethers.js, viem, etc.)
|
|
50
52
|
const hash = await walletClient.sendTransaction(tx);
|
|
51
53
|
return { status: 'success', transactionHash: hash };
|
|
52
54
|
} catch (err: unknown) {
|
|
@@ -56,58 +58,18 @@ function App() {
|
|
|
56
58
|
|
|
57
59
|
return (
|
|
58
60
|
<ChatWidget
|
|
59
|
-
account={{ address: '0x...
|
|
61
|
+
account={{ address: '0x...', chainId: 10 }}
|
|
60
62
|
onTransaction={handleTransaction}
|
|
61
63
|
/>
|
|
62
64
|
);
|
|
63
65
|
}
|
|
64
66
|
```
|
|
65
67
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
## React — Full API
|
|
69
|
-
|
|
70
|
-
### `<ChatWidget />` Props
|
|
71
|
-
|
|
72
|
-
| Prop | Type | Default | Required | Description |
|
|
73
|
-
| --------------- | ------------------------------------------------- | ---------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------- |
|
|
74
|
-
| `account` | `Account` | `undefined` | No | Connected wallet. Pass `undefined` when no wallet is connected. |
|
|
75
|
-
| `onTransaction` | `(tx: Transaction) => Promise<TransactionResult>` | `undefined` | No\* | Called when the chatbot needs to sign/send a transaction. |
|
|
76
|
-
| `position` | `'bottom-right'` \| `'bottom-left'` | `'bottom-right'` | No | Corner where the floating button appears. |
|
|
77
|
-
| `theme` | `ChatWidgetTheme` | `{}` | No | Visual customization. |
|
|
78
|
-
| `defaultOpen` | `boolean` | `false` | No | Open the chat modal on first render. |
|
|
79
|
-
| `onOpen` | `() => void` | — | No | Callback fired when the modal opens. |
|
|
80
|
-
| `onClose` | `() => void` | — | No | Callback fired when the modal closes. |
|
|
81
|
-
| `language` | `'en'` \| `'ja'` \| `'cn'` | `'en'` | No | UI language (English, Japanese, Chinese). |
|
|
82
|
-
| `rpcUrls` | `Record<number, string>` | — | No | Per-chain RPC URL overrides (`chainId → URL`). Takes priority over built-in defaults for balance queries and gas estimation. |
|
|
83
|
-
|
|
84
|
-
> \* `onTransaction` is required to execute on-chain actions (swap, send, approve, etc.). Without it, the AI can still answer questions and display information.
|
|
85
|
-
|
|
86
|
-
### Basic example
|
|
68
|
+
### Full example
|
|
87
69
|
|
|
88
70
|
```tsx
|
|
89
|
-
import { ChatWidget } from 'keyring-chatbot-agent
|
|
90
|
-
|
|
91
|
-
function App() {
|
|
92
|
-
return (
|
|
93
|
-
<ChatWidget
|
|
94
|
-
account={{ address: userAddress, chainId: 10 }}
|
|
95
|
-
onTransaction={handleTransaction}
|
|
96
|
-
language="en"
|
|
97
|
-
position="bottom-right"
|
|
98
|
-
/>
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
### Full example with all props
|
|
104
|
-
|
|
105
|
-
```tsx
|
|
106
|
-
import { ChatWidget } from 'keyring-chatbot-agent-sdk-test';
|
|
107
|
-
import type {
|
|
108
|
-
Transaction,
|
|
109
|
-
TransactionResult,
|
|
110
|
-
} from 'keyring-chatbot-agent-sdk-test';
|
|
71
|
+
import { ChatWidget } from 'keyring-chatbot-agent';
|
|
72
|
+
import type { Transaction, TransactionResult } from 'keyring-chatbot-agent';
|
|
111
73
|
|
|
112
74
|
function App() {
|
|
113
75
|
const handleTransaction = async (
|
|
@@ -150,15 +112,12 @@ function App() {
|
|
|
150
112
|
}
|
|
151
113
|
```
|
|
152
114
|
|
|
153
|
-
###
|
|
115
|
+
### With wagmi v2
|
|
154
116
|
|
|
155
117
|
```tsx
|
|
156
118
|
import { useSendTransaction, useAccount } from 'wagmi';
|
|
157
|
-
import { ChatWidget } from 'keyring-chatbot-agent
|
|
158
|
-
import type {
|
|
159
|
-
Transaction,
|
|
160
|
-
TransactionResult,
|
|
161
|
-
} from 'keyring-chatbot-agent-sdk-test';
|
|
119
|
+
import { ChatWidget } from 'keyring-chatbot-agent';
|
|
120
|
+
import type { Transaction, TransactionResult } from 'keyring-chatbot-agent';
|
|
162
121
|
|
|
163
122
|
function App() {
|
|
164
123
|
const { address, chainId } = useAccount();
|
|
@@ -188,13 +147,52 @@ function App() {
|
|
|
188
147
|
}
|
|
189
148
|
```
|
|
190
149
|
|
|
150
|
+
### `<ChatWidget />` Props
|
|
151
|
+
|
|
152
|
+
| Prop | Type | Default | Required | Description |
|
|
153
|
+
| --------------- | ------------------------------------------------- | ---------------- | -------- | ---------------------------------------------------------------------------------------------------------- |
|
|
154
|
+
| `account` | `Account` | `undefined` | No | Connected wallet. Omit when no wallet is connected. |
|
|
155
|
+
| `onTransaction` | `(tx: Transaction) => Promise<TransactionResult>` | `undefined` | \* | Called when the chatbot needs to sign/send a transaction. |
|
|
156
|
+
| `position` | `'bottom-right'` \| `'bottom-left'` | `'bottom-right'` | No | Corner where the floating button appears. |
|
|
157
|
+
| `language` | `'en'` \| `'ja'` \| `'cn'` | `'en'` | No | UI language. |
|
|
158
|
+
| `theme` | `ChatWidgetTheme` | `{}` | No | Visual customization (color, size, z-index). |
|
|
159
|
+
| `defaultOpen` | `boolean` | `false` | No | Open the chat modal on first render. |
|
|
160
|
+
| `rpcUrls` | `Record<number, string>` | — | No | Per-chain RPC URL overrides. Takes priority over built-in defaults for balance queries and gas estimation. |
|
|
161
|
+
| `onOpen` | `() => void` | — | No | Callback fired when the modal opens. |
|
|
162
|
+
| `onClose` | `() => void` | — | No | Callback fired when the modal closes. |
|
|
163
|
+
|
|
164
|
+
> \* `onTransaction` is required to execute on-chain actions (swap, send, approve, etc.). Without it, the AI can still answer questions and display information.
|
|
165
|
+
|
|
191
166
|
---
|
|
192
167
|
|
|
193
|
-
## HTML
|
|
168
|
+
## HTML / Web Component Usage
|
|
169
|
+
|
|
170
|
+
The SDK ships a **Web Component** build (`chat-widget-wc`) that can be embedded in any HTML page without a React build pipeline. The Web Component supports **the same full feature set as the React component**: wallet connection, transaction signing, RPC URL overrides, language selection, and all callbacks.
|
|
171
|
+
|
|
172
|
+
### Configuration via HTML attributes
|
|
173
|
+
|
|
174
|
+
Simple scalar values (strings, numbers, booleans) can be set directly on the HTML tag:
|
|
175
|
+
|
|
176
|
+
| Attribute | Type | Default | Description |
|
|
177
|
+
| --------------- | --------- | ---------------- | ------------------------------------------------ |
|
|
178
|
+
| `position` | `string` | `'bottom-right'` | `'bottom-right'` or `'bottom-left'` |
|
|
179
|
+
| `primary-color` | `string` | `'#007bff'` | Widget accent color (hex or any CSS color value) |
|
|
180
|
+
| `button-size` | `number` | `60` | Floating button diameter in pixels |
|
|
181
|
+
| `z-index` | `number` | `9999` | CSS `z-index` of the widget |
|
|
182
|
+
| `default-open` | `boolean` | `false` | Set to `"true"` to open the chat on page load |
|
|
183
|
+
| `language` | `string` | `'en'` | UI language: `'en'`, `'ja'`, or `'cn'` |
|
|
194
184
|
|
|
195
|
-
|
|
185
|
+
### Configuration via JavaScript properties
|
|
196
186
|
|
|
197
|
-
|
|
187
|
+
Complex objects (`account`, `rpcUrls`, callbacks) are assigned as JavaScript properties on the element. Setting any property triggers an immediate re-render.
|
|
188
|
+
|
|
189
|
+
| Property | Type | Description |
|
|
190
|
+
| --------------- | ------------------------------------------------- | ------------------------------------- |
|
|
191
|
+
| `account` | `{ address: string; chainId: number }` | Connected wallet info |
|
|
192
|
+
| `onTransaction` | `(tx: Transaction) => Promise<TransactionResult>` | Transaction signing / sending handler |
|
|
193
|
+
| `rpcUrls` | `Record<number, string>` | Per-chain RPC URL overrides |
|
|
194
|
+
| `onOpen` | `() => void` | Callback fired when the modal opens |
|
|
195
|
+
| `onClose` | `() => void` | Callback fired when the modal closes |
|
|
198
196
|
|
|
199
197
|
### Via CDN — UMD script tag
|
|
200
198
|
|
|
@@ -206,18 +204,50 @@ The web component supports visual configuration via HTML attributes (`position`,
|
|
|
206
204
|
<title>My dApp</title>
|
|
207
205
|
</head>
|
|
208
206
|
<body>
|
|
209
|
-
<h1>My Web3 App</h1>
|
|
210
|
-
|
|
211
207
|
<!-- 1. Load the bundle -->
|
|
212
|
-
<script src="https://unpkg.com/keyring-chatbot-agent
|
|
208
|
+
<script src="https://unpkg.com/keyring-chatbot-agent/dist/chat-widget-wc.umd.js"></script>
|
|
213
209
|
|
|
214
|
-
<!-- 2. Place the custom element -->
|
|
210
|
+
<!-- 2. Place the custom element with basic attributes -->
|
|
215
211
|
<chat-widget
|
|
212
|
+
id="my-chat"
|
|
216
213
|
position="bottom-right"
|
|
217
214
|
primary-color="#5B7FFF"
|
|
218
215
|
button-size="60"
|
|
219
216
|
z-index="9999"
|
|
217
|
+
language="en"
|
|
220
218
|
></chat-widget>
|
|
219
|
+
|
|
220
|
+
<!-- 3. Assign account and onTransaction via JavaScript -->
|
|
221
|
+
<script>
|
|
222
|
+
const widget = document.getElementById('my-chat');
|
|
223
|
+
|
|
224
|
+
// Set wallet info (reassign whenever the wallet changes)
|
|
225
|
+
widget.account = { address: '0xYourWalletAddress', chainId: 10 };
|
|
226
|
+
|
|
227
|
+
// Set the transaction handler
|
|
228
|
+
widget.onTransaction = async function (tx) {
|
|
229
|
+
try {
|
|
230
|
+
// Works with any provider: ethers.js, viem, MetaMask, etc.
|
|
231
|
+
const provider = new ethers.BrowserProvider(window.ethereum);
|
|
232
|
+
const signer = await provider.getSigner();
|
|
233
|
+
const txResponse = await signer.sendTransaction({
|
|
234
|
+
to: tx.to,
|
|
235
|
+
data: tx.data,
|
|
236
|
+
value: BigInt(tx.value || '0'),
|
|
237
|
+
});
|
|
238
|
+
const receipt = await txResponse.wait();
|
|
239
|
+
return { status: 'success', transactionHash: receipt.hash };
|
|
240
|
+
} catch (err) {
|
|
241
|
+
return { status: 'fail', error: err.message };
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
// Optional: override RPC URLs
|
|
246
|
+
widget.rpcUrls = {
|
|
247
|
+
10: 'https://optimism-mainnet.infura.io/v3/YOUR_KEY',
|
|
248
|
+
8453: 'https://mainnet.base.org',
|
|
249
|
+
};
|
|
250
|
+
</script>
|
|
221
251
|
</body>
|
|
222
252
|
</html>
|
|
223
253
|
```
|
|
@@ -232,54 +262,114 @@ The web component supports visual configuration via HTML attributes (`position`,
|
|
|
232
262
|
<title>My dApp</title>
|
|
233
263
|
</head>
|
|
234
264
|
<body>
|
|
235
|
-
<
|
|
236
|
-
|
|
237
|
-
|
|
265
|
+
<chat-widget
|
|
266
|
+
id="my-chat"
|
|
267
|
+
position="bottom-right"
|
|
268
|
+
language="en"
|
|
269
|
+
></chat-widget>
|
|
238
270
|
|
|
239
271
|
<script type="module">
|
|
240
|
-
import 'https://unpkg.com/keyring-chatbot-agent
|
|
241
|
-
</script>
|
|
242
|
-
</body>
|
|
243
|
-
</html>
|
|
244
|
-
```
|
|
272
|
+
import 'https://unpkg.com/keyring-chatbot-agent/dist/chat-widget-wc.es.js';
|
|
245
273
|
|
|
246
|
-
|
|
274
|
+
const widget = document.getElementById('my-chat');
|
|
247
275
|
|
|
248
|
-
|
|
249
|
-
<script src="./node_modules/keyring-chatbot-agent-sdk-test/dist/chat-widget-wc.umd.js"></script>
|
|
276
|
+
widget.account = { address: '0xYourWalletAddress', chainId: 10 };
|
|
250
277
|
|
|
251
|
-
|
|
278
|
+
widget.onTransaction = async (tx) => {
|
|
279
|
+
// handle transaction signing here
|
|
280
|
+
};
|
|
281
|
+
</script>
|
|
282
|
+
</body>
|
|
283
|
+
</html>
|
|
252
284
|
```
|
|
253
285
|
|
|
254
|
-
###
|
|
286
|
+
### Full MetaMask integration (plain HTML)
|
|
255
287
|
|
|
256
288
|
```html
|
|
257
|
-
|
|
289
|
+
<!DOCTYPE html>
|
|
290
|
+
<html lang="en">
|
|
291
|
+
<head>
|
|
292
|
+
<meta charset="UTF-8" />
|
|
293
|
+
<title>My dApp</title>
|
|
294
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/ethers/6.13.0/ethers.umd.min.js"></script>
|
|
295
|
+
<script src="https://unpkg.com/keyring-chatbot-agent/dist/chat-widget-wc.umd.js"></script>
|
|
296
|
+
</head>
|
|
297
|
+
<body>
|
|
298
|
+
<button id="connect-btn">Connect Wallet</button>
|
|
299
|
+
<chat-widget
|
|
300
|
+
id="my-chat"
|
|
301
|
+
position="bottom-right"
|
|
302
|
+
language="en"
|
|
303
|
+
></chat-widget>
|
|
258
304
|
|
|
259
|
-
<
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
305
|
+
<script>
|
|
306
|
+
const widget = document.getElementById('my-chat');
|
|
307
|
+
|
|
308
|
+
widget.onTransaction = async function (tx) {
|
|
309
|
+
try {
|
|
310
|
+
const provider = new ethers.BrowserProvider(window.ethereum);
|
|
311
|
+
const signer = await provider.getSigner();
|
|
312
|
+
const txResponse = await signer.sendTransaction({
|
|
313
|
+
to: tx.to,
|
|
314
|
+
data: tx.data,
|
|
315
|
+
value: BigInt(tx.value || '0'),
|
|
316
|
+
});
|
|
317
|
+
const receipt = await txResponse.wait();
|
|
318
|
+
return { status: 'success', transactionHash: receipt.hash };
|
|
319
|
+
} catch (err) {
|
|
320
|
+
return { status: 'fail', error: err.message };
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
document.getElementById('connect-btn').onclick = async function () {
|
|
325
|
+
if (!window.ethereum) return alert('Please install MetaMask!');
|
|
326
|
+
const provider = new ethers.BrowserProvider(window.ethereum);
|
|
327
|
+
const accounts = await provider.send('eth_requestAccounts', []);
|
|
328
|
+
const network = await provider.getNetwork();
|
|
329
|
+
widget.account = {
|
|
330
|
+
address: accounts[0],
|
|
331
|
+
chainId: Number(network.chainId),
|
|
332
|
+
};
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
// React to wallet / chain changes
|
|
336
|
+
if (window.ethereum) {
|
|
337
|
+
window.ethereum.on('accountsChanged', async (accounts) => {
|
|
338
|
+
if (accounts.length === 0) {
|
|
339
|
+
widget.account = undefined;
|
|
340
|
+
} else {
|
|
341
|
+
const provider = new ethers.BrowserProvider(window.ethereum);
|
|
342
|
+
const network = await provider.getNetwork();
|
|
343
|
+
widget.account = {
|
|
344
|
+
address: accounts[0],
|
|
345
|
+
chainId: Number(network.chainId),
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
window.ethereum.on('chainChanged', async () => {
|
|
350
|
+
const provider = new ethers.BrowserProvider(window.ethereum);
|
|
351
|
+
const network = await provider.getNetwork();
|
|
352
|
+
const accounts = await provider.listAccounts();
|
|
353
|
+
if (accounts.length > 0) {
|
|
354
|
+
widget.account = {
|
|
355
|
+
address: accounts[0].address,
|
|
356
|
+
chainId: Number(network.chainId),
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
</script>
|
|
362
|
+
</body>
|
|
363
|
+
</html>
|
|
264
364
|
```
|
|
265
365
|
|
|
266
|
-
### Web Component — HTML Attributes
|
|
267
|
-
|
|
268
|
-
| Attribute | Type | Default | Description |
|
|
269
|
-
| --------------- | --------- | ---------------- | --------------------------------------------- |
|
|
270
|
-
| `position` | `string` | `'bottom-right'` | `'bottom-right'` or `'bottom-left'` |
|
|
271
|
-
| `primary-color` | `string` | `'#007bff'` | Widget accent color (hex or CSS color) |
|
|
272
|
-
| `button-size` | `number` | `60` | Floating button diameter in pixels |
|
|
273
|
-
| `z-index` | `number` | `9999` | CSS `z-index` of the widget |
|
|
274
|
-
| `default-open` | `boolean` | `false` | Set to `"true"` to open the chat on page load |
|
|
275
|
-
|
|
276
366
|
---
|
|
277
367
|
|
|
278
368
|
## Type Definitions
|
|
279
369
|
|
|
280
370
|
```typescript
|
|
281
371
|
interface Account {
|
|
282
|
-
address: string; // Wallet address (0x
|
|
372
|
+
address: string; // Wallet address (0x...)
|
|
283
373
|
chainId: number | string; // EIP-155 chain ID
|
|
284
374
|
}
|
|
285
375
|
|
|
@@ -287,7 +377,7 @@ interface Transaction {
|
|
|
287
377
|
from: string;
|
|
288
378
|
to: string;
|
|
289
379
|
data: string; // ABI-encoded calldata (hex)
|
|
290
|
-
value: string; // Native amount in wei
|
|
380
|
+
value: string; // Native token amount in wei
|
|
291
381
|
gasLimit?: string;
|
|
292
382
|
gasPrice?: string;
|
|
293
383
|
maxFeePerGas?: string;
|
|
@@ -303,7 +393,7 @@ interface TransactionResult {
|
|
|
303
393
|
}
|
|
304
394
|
|
|
305
395
|
interface ChatWidgetTheme {
|
|
306
|
-
primaryColor?: string; // Hex / CSS color
|
|
396
|
+
primaryColor?: string; // Hex / CSS color
|
|
307
397
|
buttonSize?: number; // Floating button size in px
|
|
308
398
|
zIndex?: number; // CSS z-index
|
|
309
399
|
}
|
|
@@ -330,34 +420,35 @@ type Language = 'en' | 'ja' | 'cn';
|
|
|
330
420
|
|
|
331
421
|
## AI Capabilities
|
|
332
422
|
|
|
333
|
-
The embedded AI (GPT-4.1-mini via Moralis Cortex) understands natural language and routes to on-chain actions
|
|
423
|
+
The embedded AI (GPT-4.1-mini via Moralis Cortex) understands natural language and automatically routes to on-chain actions:
|
|
334
424
|
|
|
335
|
-
|
|
|
336
|
-
|
|
|
337
|
-
| "Swap 1 ETH to USDC"
|
|
338
|
-
| "Swap max USDT to ETH"
|
|
339
|
-
| "Buy WBTC"
|
|
340
|
-
| "Send 10 USDC to 0x
|
|
341
|
-
| "Send 0.05 ETH to 0x
|
|
342
|
-
| "Wrap 1 ETH" / "Unwrap 0.5 WETH"
|
|
343
|
-
| "Show my NFTs"
|
|
344
|
-
| "Send my Bored Ape #1234 to 0x
|
|
345
|
-
| "What is the gas fee?"
|
|
346
|
-
| "What tokens are trending?"
|
|
425
|
+
| What the user says | Action performed |
|
|
426
|
+
| ---------------------------------- | ------------------------------------ |
|
|
427
|
+
| "Swap 1 ETH to USDC" | Token swap via deBridge |
|
|
428
|
+
| "Swap max USDT to ETH" | Swap with full-balance resolution |
|
|
429
|
+
| "Buy WBTC" | Trending token list for selection |
|
|
430
|
+
| "Send 10 USDC to 0x..." | ERC-20 transfer |
|
|
431
|
+
| "Send 0.05 ETH to 0x..." | Native token transfer |
|
|
432
|
+
| "Wrap 1 ETH" / "Unwrap 0.5 WETH" | Wrap / unwrap native token |
|
|
433
|
+
| "Show my NFTs" | Link to NFT gallery |
|
|
434
|
+
| "Send my Bored Ape #1234 to 0x..." | ERC-721 / ERC-1155 transfer |
|
|
435
|
+
| "What is the current gas fee?" | General blockchain Q&A |
|
|
436
|
+
| "What tokens are trending?" | Trending list with quick-buy buttons |
|
|
437
|
+
| "What is my balance?" | Token list with USD values |
|
|
347
438
|
|
|
348
|
-
### Smart
|
|
439
|
+
### Smart swap flow
|
|
349
440
|
|
|
350
441
|
The AI handles missing parameters gracefully:
|
|
351
442
|
|
|
352
|
-
|
|
|
353
|
-
|
|
|
354
|
-
| token_in + token_out + amount
|
|
355
|
-
| token_in + token_out
|
|
356
|
-
| token_out only
|
|
357
|
-
| token_in only
|
|
358
|
-
| Neither
|
|
359
|
-
| ERC-20 needs approval
|
|
360
|
-
| Insufficient balance
|
|
443
|
+
| Available information | Behaviour |
|
|
444
|
+
| -------------------------------- | --------------------------------------------- |
|
|
445
|
+
| token_in + token_out + amount | Full auto-swap: estimate → confirm → execute |
|
|
446
|
+
| token_in + token_out (no amount) | Shows 25 / 50 / 75 / 100 % amount selector |
|
|
447
|
+
| token_out only | Shows wallet balances to choose source token |
|
|
448
|
+
| token_in only | Shows trending tokens to choose destination |
|
|
449
|
+
| Neither token specified | Asks the user to specify both tokens |
|
|
450
|
+
| ERC-20 needs approval | Prompts Approve step before swap |
|
|
451
|
+
| Insufficient balance or fee | Warning message, no confirmation button shown |
|
|
361
452
|
|
|
362
453
|
---
|
|
363
454
|
|
|
@@ -411,7 +502,7 @@ yarn build:react
|
|
|
411
502
|
# Build Web Component bundle only
|
|
412
503
|
yarn build:wc
|
|
413
504
|
|
|
414
|
-
# Watch mode (auto-rebuild
|
|
505
|
+
# Watch mode (auto-rebuild on change)
|
|
415
506
|
yarn watch
|
|
416
507
|
|
|
417
508
|
# Lint
|
|
@@ -429,34 +520,35 @@ yarn format
|
|
|
429
520
|
```
|
|
430
521
|
src/
|
|
431
522
|
├── components/
|
|
432
|
-
│ ├── ActionForm.tsx
|
|
433
|
-
│ ├── ChatButton.tsx
|
|
434
|
-
│ ├── ChatModal.tsx
|
|
435
|
-
│ ├── ChatWidget.tsx
|
|
436
|
-
│ ├── MessageContent.tsx
|
|
523
|
+
│ ├── ActionForm.tsx # Inline transaction forms (send, approve, ...)
|
|
524
|
+
│ ├── ChatButton.tsx # Floating action button
|
|
525
|
+
│ ├── ChatModal.tsx # Chat UI + all AI and on-chain logic
|
|
526
|
+
│ ├── ChatWidget.tsx # Root component — public API entry point
|
|
527
|
+
│ ├── MessageContent.tsx # Markdown message renderer
|
|
437
528
|
│ ├── ScrollToBottomButton.tsx
|
|
438
529
|
│ └── WalletUserInfo.tsx
|
|
439
530
|
├── constants/
|
|
440
|
-
│ ├── agentActions.ts
|
|
441
|
-
│ ├── chains.ts
|
|
442
|
-
│ ├── storage.ts
|
|
443
|
-
│ └── systemPrompt.ts
|
|
531
|
+
│ ├── agentActions.ts # AgentActionType definitions + form schemas
|
|
532
|
+
│ ├── chains.ts # Supported chain configs
|
|
533
|
+
│ ├── storage.ts # localStorage key constants
|
|
534
|
+
│ └── systemPrompt.ts # AI system prompt builder
|
|
444
535
|
├── contexts/
|
|
445
|
-
│ ├── ConfigContext.tsx
|
|
446
|
-
│ ├── ConnectContext.tsx
|
|
447
|
-
│ └── LanguageContext.tsx
|
|
536
|
+
│ ├── ConfigContext.tsx # RPC URLs + theme config context
|
|
537
|
+
│ ├── ConnectContext.tsx # Wallet account context
|
|
538
|
+
│ └── LanguageContext.tsx # i18n language context
|
|
448
539
|
├── hooks/
|
|
449
|
-
│ └── useChatMessages.ts
|
|
540
|
+
│ └── useChatMessages.ts # Chat message state management
|
|
450
541
|
├── services/
|
|
451
|
-
│ ├── BaseApi.ts
|
|
452
|
-
│ ├── deBridge.ts
|
|
453
|
-
│ ├──
|
|
454
|
-
│ ├──
|
|
455
|
-
│
|
|
542
|
+
│ ├── BaseApi.ts # Base HTTP client
|
|
543
|
+
│ ├── deBridge.ts # deBridge swap quote + transaction API
|
|
544
|
+
│ ├── gemini.ts # Gemini AI: question classification, general chat
|
|
545
|
+
│ ├── moralis.ts # Moralis AI chat, wallet balances, NFTs, metadata
|
|
546
|
+
│ ├── token.ts # Token info + trending data
|
|
547
|
+
│ └── web3.ts # Transaction builder, fee estimation, allowance check
|
|
456
548
|
├── types/
|
|
457
|
-
│ └── index.ts
|
|
458
|
-
├── lib.tsx
|
|
459
|
-
└── web-component.tsx
|
|
549
|
+
│ └── index.ts # All public TypeScript interfaces
|
|
550
|
+
├── lib.tsx # React library entry point
|
|
551
|
+
└── web-component.tsx # Web Component entry point
|
|
460
552
|
```
|
|
461
553
|
|
|
462
554
|
---
|