clawchain-wallet 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,528 @@
1
+ /**
2
+ * ClawChain Agent Tools 定义
3
+ *
4
+ * 使用 OpenClaw Plugin SDK 的类型和辅助函数
5
+ * 支持按 Agent 隔离钱包存储
6
+ */
7
+ import path from "node:path";
8
+ import { Type } from "@sinclair/typebox";
9
+ import { jsonResult } from "openclaw/plugin-sdk";
10
+ import { executeCommand } from "./executor.js";
11
+ /**
12
+ * 根据上下文确定钱包存储目录
13
+ *
14
+ * 优先级:
15
+ * 1. 显式配置的 walletsDir
16
+ * 2. Agent 工作区目录下的 .wallets
17
+ * 3. 默认目录(由 Python CLI 决定,通常是 ~/.clawchain/wallets)
18
+ */
19
+ function resolveWalletsDir(baseOptions, ctx) {
20
+ // 如果显式配置了 walletsDir,优先使用
21
+ if (baseOptions.walletsDir) {
22
+ return baseOptions.walletsDir;
23
+ }
24
+ // 否则使用 agent 工作区目录
25
+ if (ctx.workspaceDir) {
26
+ return path.join(ctx.workspaceDir, ".wallets");
27
+ }
28
+ // 都没有则返回 undefined,让 Python CLI 使用默认值
29
+ return undefined;
30
+ }
31
+ /**
32
+ * 创建所有 ClawChain 工具工厂
33
+ *
34
+ * 每个工厂函数会根据当前 agent 上下文确定钱包存储目录
35
+ */
36
+ export function createClawChainToolFactories(baseOptions) {
37
+ return [
38
+ createWalletCreateToolFactory(baseOptions),
39
+ createWalletImportToolFactory(baseOptions),
40
+ createWalletListToolFactory(baseOptions),
41
+ createWalletInfoToolFactory(baseOptions),
42
+ createWalletDeleteToolFactory(baseOptions),
43
+ createWalletRenameToolFactory(baseOptions),
44
+ createWalletExportToolFactory(baseOptions),
45
+ createBalanceQueryToolFactory(baseOptions),
46
+ createTransferToolFactory(baseOptions),
47
+ createTxInfoToolFactory(baseOptions),
48
+ createTxHistoryToolFactory(baseOptions),
49
+ createChainInfoToolFactory(baseOptions),
50
+ createBlockInfoToolFactory(baseOptions),
51
+ createClaimAirdropToolFactory(baseOptions),
52
+ ];
53
+ }
54
+ // ==================== 钱包创建工具 ====================
55
+ function createWalletCreateToolFactory(baseOptions) {
56
+ return (ctx) => {
57
+ const options = {
58
+ ...baseOptions,
59
+ walletsDir: resolveWalletsDir(baseOptions, ctx),
60
+ };
61
+ return {
62
+ name: "clawchain_wallet_create",
63
+ label: "ClawChain Wallet Create",
64
+ description: `在 ClawChain 上创建新钱包。创建后会自动保存到本地,返回钱包地址和私钥。
65
+
66
+ 【重要】钱包命名规则:
67
+ 1. 强烈建议为每个钱包指定一个**唯一且有意义的名称**,方便后续管理和区分
68
+ 2. 名称必须是之前未使用过的,否则会报错
69
+ 3. 如果不指定名称,系统会自动生成名称(格式:wallet-01, wallet-02 等)
70
+ 4. 创建前可以先调用 clawchain_wallet_list 查看已有钱包名称,避免重复
71
+
72
+ 建议的命名方式:
73
+ - 按用途命名:'主钱包'、'储蓄钱包'、'交易钱包'、'测试钱包'
74
+ - 按编号命名:'钱包-1'、'钱包-2' 等`,
75
+ parameters: Type.Object({
76
+ name: Type.Optional(Type.String({
77
+ description: "钱包名称(必须唯一)。强烈建议指定一个有意义且未使用过的名称。如不指定,系统会自动生成 wallet-XX 格式的名称",
78
+ })),
79
+ }),
80
+ execute: async (_toolCallId, args) => {
81
+ const params = args;
82
+ const cmdArgs = {};
83
+ if (params.name) {
84
+ cmdArgs.name = params.name;
85
+ }
86
+ const result = executeCommand(options, "wallet-create", cmdArgs);
87
+ return jsonResult(result);
88
+ },
89
+ };
90
+ };
91
+ }
92
+ // ==================== 钱包导入工具 ====================
93
+ function createWalletImportToolFactory(baseOptions) {
94
+ return (ctx) => {
95
+ const options = {
96
+ ...baseOptions,
97
+ walletsDir: resolveWalletsDir(baseOptions, ctx),
98
+ };
99
+ return {
100
+ name: "clawchain_wallet_import",
101
+ label: "ClawChain Wallet Import",
102
+ description: `通过私钥导入已有的钱包到 ClawChain。
103
+ 导入后钱包会保存到本地,可以像新创建的钱包一样使用。
104
+
105
+ 【重要】钱包命名规则:
106
+ 1. 强烈建议为导入的钱包指定一个**唯一且有意义的名称**
107
+ 2. 名称必须是之前未使用过的,否则会报错
108
+ 3. 如果不指定名称,系统会自动生成名称(格式:wallet-01, wallet-02 等)
109
+ 4. 导入前可以先调用 clawchain_wallet_list 查看已有钱包名称,避免重复`,
110
+ parameters: Type.Object({
111
+ private_key: Type.String({
112
+ description: "要导入的钱包私钥(支持带或不带 0x 前缀)",
113
+ }),
114
+ name: Type.Optional(Type.String({
115
+ description: "钱包名称(必须唯一)。强烈建议指定一个有意义且未使用过的名称。如不指定,系统会自动生成 wallet-XX 格式的名称",
116
+ })),
117
+ }),
118
+ execute: async (_toolCallId, args) => {
119
+ const params = args;
120
+ const cmdArgs = {
121
+ private_key: params.private_key,
122
+ };
123
+ if (params.name) {
124
+ cmdArgs.name = params.name;
125
+ }
126
+ const result = executeCommand(options, "wallet-import", cmdArgs);
127
+ return jsonResult(result);
128
+ },
129
+ };
130
+ };
131
+ }
132
+ // ==================== 钱包列表工具 ====================
133
+ function createWalletListToolFactory(baseOptions) {
134
+ return (ctx) => {
135
+ const options = {
136
+ ...baseOptions,
137
+ walletsDir: resolveWalletsDir(baseOptions, ctx),
138
+ };
139
+ return {
140
+ name: "clawchain_wallet_list",
141
+ label: "ClawChain Wallet List",
142
+ description: `列出所有已创建或导入的 ClawChain 钱包。
143
+ 可以选择是否显示每个钱包的 CLAW 余额。
144
+ 返回钱包名称、地址、创建时间等信息。`,
145
+ parameters: Type.Object({
146
+ show_balance: Type.Optional(Type.Boolean({
147
+ description: "是否显示每个钱包的 CLAW 余额(查询余额需要联网,可能稍慢)",
148
+ default: false,
149
+ })),
150
+ }),
151
+ execute: async (_toolCallId, args) => {
152
+ const params = args;
153
+ const cmdArgs = {
154
+ show_balance: params.show_balance ?? false,
155
+ };
156
+ const result = executeCommand(options, "wallet-list", cmdArgs);
157
+ return jsonResult(result);
158
+ },
159
+ };
160
+ };
161
+ }
162
+ // ==================== 钱包详情工具 ====================
163
+ function createWalletInfoToolFactory(baseOptions) {
164
+ return (ctx) => {
165
+ const options = {
166
+ ...baseOptions,
167
+ walletsDir: resolveWalletsDir(baseOptions, ctx),
168
+ };
169
+ return {
170
+ name: "clawchain_wallet_info",
171
+ label: "ClawChain Wallet Info",
172
+ description: `获取指定钱包的详细信息,包括地址、余额、创建时间等。
173
+ 可以通过钱包名称或钱包 ID 来查询。
174
+ 默认不显示私钥,需要显示私钥时设置 show_private_key 为 true。`,
175
+ parameters: Type.Object({
176
+ identifier: Type.String({
177
+ description: "钱包名称或钱包 ID",
178
+ }),
179
+ show_private_key: Type.Optional(Type.Boolean({
180
+ description: "是否显示私钥(敏感信息,谨慎使用)",
181
+ default: false,
182
+ })),
183
+ }),
184
+ execute: async (_toolCallId, args) => {
185
+ const params = args;
186
+ const cmdArgs = {
187
+ identifier: params.identifier,
188
+ show_private_key: params.show_private_key ?? false,
189
+ };
190
+ const result = executeCommand(options, "wallet-info", cmdArgs);
191
+ return jsonResult(result);
192
+ },
193
+ };
194
+ };
195
+ }
196
+ // ==================== 钱包删除工具 ====================
197
+ function createWalletDeleteToolFactory(baseOptions) {
198
+ return (ctx) => {
199
+ const options = {
200
+ ...baseOptions,
201
+ walletsDir: resolveWalletsDir(baseOptions, ctx),
202
+ };
203
+ return {
204
+ name: "clawchain_wallet_delete",
205
+ label: "ClawChain Wallet Delete",
206
+ description: `删除指定的钱包。删除前会自动备份到 deleted 目录。
207
+ 可以通过钱包名称或钱包 ID 来指定要删除的钱包。
208
+ 注意:删除后钱包将无法直接使用,但私钥备份仍保留。`,
209
+ parameters: Type.Object({
210
+ identifier: Type.String({
211
+ description: "要删除的钱包名称或钱包 ID",
212
+ }),
213
+ }),
214
+ execute: async (_toolCallId, args) => {
215
+ const params = args;
216
+ const cmdArgs = {
217
+ identifier: params.identifier,
218
+ };
219
+ const result = executeCommand(options, "wallet-delete", cmdArgs);
220
+ return jsonResult(result);
221
+ },
222
+ };
223
+ };
224
+ }
225
+ // ==================== 钱包重命名工具 ====================
226
+ function createWalletRenameToolFactory(baseOptions) {
227
+ return (ctx) => {
228
+ const options = {
229
+ ...baseOptions,
230
+ walletsDir: resolveWalletsDir(baseOptions, ctx),
231
+ };
232
+ return {
233
+ name: "clawchain_wallet_rename",
234
+ label: "ClawChain Wallet Rename",
235
+ description: `重命名指定的钱包。
236
+ 可以通过钱包名称或钱包 ID 来指定要重命名的钱包。`,
237
+ parameters: Type.Object({
238
+ identifier: Type.String({
239
+ description: "要重命名的钱包名称或钱包 ID",
240
+ }),
241
+ new_name: Type.String({
242
+ description: "新的钱包名称",
243
+ }),
244
+ }),
245
+ execute: async (_toolCallId, args) => {
246
+ const params = args;
247
+ const cmdArgs = {
248
+ identifier: params.identifier,
249
+ new_name: params.new_name,
250
+ };
251
+ const result = executeCommand(options, "wallet-rename", cmdArgs);
252
+ return jsonResult(result);
253
+ },
254
+ };
255
+ };
256
+ }
257
+ // ==================== 钱包导出工具 ====================
258
+ function createWalletExportToolFactory(baseOptions) {
259
+ return (ctx) => {
260
+ const options = {
261
+ ...baseOptions,
262
+ walletsDir: resolveWalletsDir(baseOptions, ctx),
263
+ };
264
+ return {
265
+ name: "clawchain_wallet_export",
266
+ label: "ClawChain Wallet Export",
267
+ description: `导出钱包的私钥。用于备份或在其他地方导入钱包。
268
+ 警告:私钥是敏感信息,请勿泄露给他人!`,
269
+ parameters: Type.Object({
270
+ identifier: Type.String({
271
+ description: "要导出的钱包名称或钱包 ID",
272
+ }),
273
+ }),
274
+ execute: async (_toolCallId, args) => {
275
+ const params = args;
276
+ const cmdArgs = {
277
+ identifier: params.identifier,
278
+ };
279
+ const result = executeCommand(options, "wallet-export", cmdArgs);
280
+ return jsonResult(result);
281
+ },
282
+ };
283
+ };
284
+ }
285
+ // ==================== 余额查询工具 ====================
286
+ function createBalanceQueryToolFactory(baseOptions) {
287
+ return (ctx) => {
288
+ const options = {
289
+ ...baseOptions,
290
+ walletsDir: resolveWalletsDir(baseOptions, ctx),
291
+ };
292
+ return {
293
+ name: "clawchain_balance",
294
+ label: "ClawChain Balance",
295
+ description: `查询 ClawChain 上指定地址或钱包的 CLAW 余额。
296
+ 可以输入钱包名称、钱包 ID 或直接输入地址(0x 开头)。
297
+ 返回余额(CLAW 和 Wei 两种单位)。`,
298
+ parameters: Type.Object({
299
+ address: Type.String({
300
+ description: "钱包地址(0x 开头)、钱包名称或钱包 ID",
301
+ }),
302
+ }),
303
+ execute: async (_toolCallId, args) => {
304
+ const params = args;
305
+ const cmdArgs = {
306
+ address: params.address,
307
+ };
308
+ const result = executeCommand(options, "balance", cmdArgs);
309
+ return jsonResult(result);
310
+ },
311
+ };
312
+ };
313
+ }
314
+ // ==================== 转账工具 ====================
315
+ function createTransferToolFactory(baseOptions) {
316
+ return (ctx) => {
317
+ const options = {
318
+ ...baseOptions,
319
+ walletsDir: resolveWalletsDir(baseOptions, ctx),
320
+ };
321
+ return {
322
+ name: "clawchain_transfer",
323
+ label: "ClawChain Transfer",
324
+ description: `在 ClawChain 上进行 CLAW 转账。
325
+ 从指定钱包转账到目标地址或另一个钱包。
326
+ 发送方必须是本地已有的钱包(通过名称或 ID 指定)。
327
+ 接收方可以是地址、钱包名称或钱包 ID。`,
328
+ parameters: Type.Object({
329
+ from_wallet: Type.String({
330
+ description: "发送方钱包名称或钱包 ID(必须是本地钱包)",
331
+ }),
332
+ to: Type.String({
333
+ description: "接收方地址(0x 开头)、钱包名称或钱包 ID",
334
+ }),
335
+ amount: Type.Number({
336
+ description: "转账金额(单位:CLAW)",
337
+ }),
338
+ wait: Type.Optional(Type.Boolean({
339
+ description: "是否等待交易确认(默认不等待,立即返回交易哈希)",
340
+ default: false,
341
+ })),
342
+ }),
343
+ execute: async (_toolCallId, args) => {
344
+ const params = args;
345
+ const cmdArgs = {
346
+ from_wallet: params.from_wallet,
347
+ to: params.to,
348
+ amount: params.amount,
349
+ wait: params.wait ?? false,
350
+ };
351
+ const execOptions = { ...options, timeout: 180000 };
352
+ const result = executeCommand(execOptions, "transfer", cmdArgs);
353
+ return jsonResult(result);
354
+ },
355
+ };
356
+ };
357
+ }
358
+ // ==================== 交易详情工具 ====================
359
+ function createTxInfoToolFactory(baseOptions) {
360
+ return (ctx) => {
361
+ const options = {
362
+ ...baseOptions,
363
+ walletsDir: resolveWalletsDir(baseOptions, ctx),
364
+ };
365
+ return {
366
+ name: "clawchain_tx_info",
367
+ label: "ClawChain Transaction Info",
368
+ description: `查询 ClawChain 上指定交易的详细信息。
369
+ 输入交易哈希,返回发送方、接收方、金额、状态等信息。`,
370
+ parameters: Type.Object({
371
+ hash: Type.String({
372
+ description: "交易哈希(0x 开头)",
373
+ }),
374
+ }),
375
+ execute: async (_toolCallId, args) => {
376
+ const params = args;
377
+ const cmdArgs = {
378
+ hash: params.hash,
379
+ };
380
+ const result = executeCommand(options, "tx-info", cmdArgs);
381
+ return jsonResult(result);
382
+ },
383
+ };
384
+ };
385
+ }
386
+ // ==================== 交易历史工具 ====================
387
+ function createTxHistoryToolFactory(baseOptions) {
388
+ return (ctx) => {
389
+ const options = {
390
+ ...baseOptions,
391
+ walletsDir: resolveWalletsDir(baseOptions, ctx),
392
+ };
393
+ return {
394
+ name: "clawchain_tx_history",
395
+ label: "ClawChain Transaction History",
396
+ description: `查询指定地址或钱包的交易历史。
397
+ 扫描最近的区块,找出与该地址相关的所有交易。
398
+ 注意:扫描大量区块可能需要较长时间。`,
399
+ parameters: Type.Object({
400
+ address: Type.String({
401
+ description: "钱包地址、钱包名称或钱包 ID",
402
+ }),
403
+ blocks: Type.Optional(Type.Number({
404
+ description: "扫描的区块数量(默认 1000)",
405
+ default: 1000,
406
+ })),
407
+ limit: Type.Optional(Type.Number({
408
+ description: "返回的交易数量限制(默认 20)",
409
+ default: 20,
410
+ })),
411
+ }),
412
+ execute: async (_toolCallId, args) => {
413
+ const params = args;
414
+ const cmdArgs = {
415
+ address: params.address,
416
+ blocks: params.blocks ?? 1000,
417
+ limit: params.limit ?? 20,
418
+ };
419
+ const execOptions = { ...options, timeout: 120000 };
420
+ const result = executeCommand(execOptions, "tx-history", cmdArgs);
421
+ return jsonResult(result);
422
+ },
423
+ };
424
+ };
425
+ }
426
+ // ==================== 链信息工具 ====================
427
+ function createChainInfoToolFactory(baseOptions) {
428
+ return (ctx) => {
429
+ const options = {
430
+ ...baseOptions,
431
+ walletsDir: resolveWalletsDir(baseOptions, ctx),
432
+ };
433
+ return {
434
+ name: "clawchain_info",
435
+ label: "ClawChain Info",
436
+ description: `获取 ClawChain 的基本信息,包括:
437
+ - 链名称:ClawChain
438
+ - 代币符号:CLAW
439
+ - RPC 地址
440
+ - Chain ID
441
+ - 连接状态
442
+ - 最新区块号
443
+ - 当前 Gas 价格`,
444
+ parameters: Type.Object({}),
445
+ execute: async () => {
446
+ const result = executeCommand(options, "chain-info", {});
447
+ return jsonResult(result);
448
+ },
449
+ };
450
+ };
451
+ }
452
+ // ==================== 区块信息工具 ====================
453
+ function createBlockInfoToolFactory(baseOptions) {
454
+ return (ctx) => {
455
+ const options = {
456
+ ...baseOptions,
457
+ walletsDir: resolveWalletsDir(baseOptions, ctx),
458
+ };
459
+ return {
460
+ name: "clawchain_block_info",
461
+ label: "ClawChain Block Info",
462
+ description: `查询 ClawChain 上指定区块的信息。
463
+ 可以输入区块号或 "latest" 获取最新区块。
464
+ 返回区块哈希、时间戳、交易数量等信息。`,
465
+ parameters: Type.Object({
466
+ number: Type.Optional(Type.String({
467
+ description: "区块号或 'latest'(默认为 latest)",
468
+ default: "latest",
469
+ })),
470
+ }),
471
+ execute: async (_toolCallId, args) => {
472
+ const params = args;
473
+ const cmdArgs = {
474
+ number: params.number || "latest",
475
+ };
476
+ const result = executeCommand(options, "block-info", cmdArgs);
477
+ return jsonResult(result);
478
+ },
479
+ };
480
+ };
481
+ }
482
+ // ==================== 领取空投工具 ====================
483
+ function createClaimAirdropToolFactory(baseOptions) {
484
+ return (ctx) => {
485
+ const options = {
486
+ ...baseOptions,
487
+ walletsDir: resolveWalletsDir(baseOptions, ctx),
488
+ };
489
+ return {
490
+ name: "clawchain_claim_airdrop",
491
+ label: "ClawChain Claim Airdrop",
492
+ description: `通过 moltbook 发帖领取 CLAW 空投。
493
+
494
+ 【重要】领取空投的完整流程(必须按顺序执行):
495
+
496
+ 第一步:确保有 ClawChain 钱包
497
+ - 调用 clawchain_wallet_list 查看现有钱包
498
+ - 如果没有钱包,调用 clawchain_wallet_create 创建一个
499
+ - 记住钱包地址
500
+
501
+ 第二步:发布帖子
502
+ - 在 moltbook 上发布一个帖子
503
+ - 帖子内容必须包含你的钱包地址
504
+ - 例如: "申请 CLAW 空投,我的钱包地址: 0x1234...abcd"
505
+ - 获取帖子的完整 URL
506
+
507
+ 第三步:调用此工具领取空投
508
+ - 将帖子的 URL 传入此工具
509
+
510
+ 【注意事项】
511
+ - 帖子内容必须包含有效的钱包地址
512
+ - URL 必须是 moltbook.com 的链接`,
513
+ parameters: Type.Object({
514
+ post_url: Type.String({
515
+ description: "moltbook 帖子或回复的完整 URL,例如: https://www.moltbook.com/post/xxx-xxx-xxx",
516
+ }),
517
+ }),
518
+ execute: async (_toolCallId, args) => {
519
+ const params = args;
520
+ const cmdArgs = {
521
+ post_url: params.post_url,
522
+ };
523
+ const result = executeCommand(options, "claim-airdrop", cmdArgs);
524
+ return jsonResult(result);
525
+ },
526
+ };
527
+ };
528
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * ClawChain Plugin 类型定义
3
+ */
4
+ export interface ClawChainConfig {
5
+ walletsDir?: string;
6
+ }
7
+ export interface CommandResult {
8
+ success: boolean;
9
+ error?: string;
10
+ [key: string]: unknown;
11
+ }
12
+ export interface WalletInfo {
13
+ id: string;
14
+ name: string;
15
+ address: string;
16
+ created_at: string;
17
+ imported?: boolean;
18
+ balance?: string;
19
+ balance_wei?: string;
20
+ }
21
+ export interface TransactionInfo {
22
+ hash: string;
23
+ from: string;
24
+ to: string;
25
+ value: string;
26
+ gas?: number;
27
+ gas_price?: string;
28
+ nonce?: number;
29
+ block_number?: number;
30
+ status?: string;
31
+ }
32
+ export interface ChainInfo {
33
+ name: string;
34
+ token_symbol: string;
35
+ rpc_url: string;
36
+ chain_id: number;
37
+ connected: boolean;
38
+ latest_block?: number;
39
+ gas_price?: string;
40
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * ClawChain Plugin 类型定义
3
+ */
4
+ export {};
package/index.ts ADDED
@@ -0,0 +1,103 @@
1
+ /**
2
+ * ClawChain Plugin for OpenClaw
3
+ *
4
+ * ClawChain 私有链钱包管理插件
5
+ * 支持创建钱包、导入钱包、余额查询、转账等功能
6
+ *
7
+ * 特性:
8
+ * - 按 Agent 隔离钱包存储(每个 agent 的钱包存储在其工作区的 .wallets 目录)
9
+ *
10
+ * 固定配置:
11
+ * - RPC URL: https://n1.clawchain.net
12
+ * - Chain ID: 1911
13
+ * - 代币名称: CLAW
14
+ * - 链名称: ClawChain
15
+ */
16
+
17
+ import path from "node:path";
18
+ import { fileURLToPath } from "node:url";
19
+ import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
20
+ import { createClawChainToolFactories } from "./src/tools.js";
21
+ import type { ClawChainConfig } from "./src/types.js";
22
+
23
+ // 获取当前文件所在目录
24
+ const __filename = fileURLToPath(import.meta.url);
25
+ const __dirname = path.dirname(__filename);
26
+
27
+ const plugin = {
28
+ id: "clawchain-wallet",
29
+ name: "ClawChain Wallet",
30
+ description: "ClawChain 私有链钱包管理工具 - 支持创建钱包、导入钱包、余额查询、转账等功能",
31
+ version: "1.0.0",
32
+
33
+ register(api: OpenClawPluginApi) {
34
+ const pluginConfig = api.pluginConfig as ClawChainConfig | undefined;
35
+
36
+ // Python 脚本路径
37
+ const pythonScript = path.join(__dirname, "python", "clawchain_cli.py");
38
+
39
+ // 显式配置的钱包存储目录(可选,优先级最高)
40
+ const walletsDir = pluginConfig?.walletsDir;
41
+
42
+ api.logger.info("[ClawChain] Plugin initializing...");
43
+ api.logger.info(`[ClawChain] Python script: ${pythonScript}`);
44
+ if (walletsDir) {
45
+ api.logger.info(`[ClawChain] Configured wallets directory: ${walletsDir}`);
46
+ } else {
47
+ api.logger.info("[ClawChain] Wallets will be stored in each agent's workspace (.wallets)");
48
+ }
49
+
50
+ // 创建基础执行器选项
51
+ const baseExecutorOptions = {
52
+ pythonScript,
53
+ walletsDir,
54
+ timeout: 60000,
55
+ };
56
+
57
+ // 获取所有工具工厂并注册
58
+ const toolFactories = createClawChainToolFactories(baseExecutorOptions);
59
+
60
+ const toolNames = [
61
+ "clawchain_wallet_create",
62
+ "clawchain_wallet_import",
63
+ "clawchain_wallet_list",
64
+ "clawchain_wallet_info",
65
+ "clawchain_wallet_delete",
66
+ "clawchain_wallet_rename",
67
+ "clawchain_wallet_export",
68
+ "clawchain_balance",
69
+ "clawchain_transfer",
70
+ "clawchain_tx_info",
71
+ "clawchain_tx_history",
72
+ "clawchain_info",
73
+ "clawchain_block_info",
74
+ "clawchain_claim_airdrop",
75
+ ];
76
+
77
+ for (let i = 0; i < toolFactories.length; i++) {
78
+ const factory = toolFactories[i];
79
+ // 注册工厂函数,OpenClaw 会在调用时传入上下文
80
+ api.registerTool(factory, { name: toolNames[i] });
81
+ api.logger.info(`[ClawChain] Registered tool: ${toolNames[i]}`);
82
+ }
83
+
84
+ api.logger.info(`[ClawChain] Plugin loaded successfully. ${toolFactories.length} tools registered.`);
85
+ api.logger.info("[ClawChain] Available tools:");
86
+ api.logger.info(" - clawchain_wallet_create: 创建新钱包");
87
+ api.logger.info(" - clawchain_wallet_import: 导入钱包");
88
+ api.logger.info(" - clawchain_wallet_list: 列出所有钱包");
89
+ api.logger.info(" - clawchain_wallet_info: 获取钱包详情");
90
+ api.logger.info(" - clawchain_wallet_delete: 删除钱包");
91
+ api.logger.info(" - clawchain_wallet_rename: 重命名钱包");
92
+ api.logger.info(" - clawchain_wallet_export: 导出钱包私钥");
93
+ api.logger.info(" - clawchain_balance: 查询余额");
94
+ api.logger.info(" - clawchain_transfer: 转账 CLAW");
95
+ api.logger.info(" - clawchain_tx_info: 查询交易详情");
96
+ api.logger.info(" - clawchain_tx_history: 查询交易历史");
97
+ api.logger.info(" - clawchain_info: 获取链信息");
98
+ api.logger.info(" - clawchain_block_info: 查询区块信息");
99
+ api.logger.info(" - clawchain_claim_airdrop: 领取 CLAW 空投");
100
+ },
101
+ };
102
+
103
+ export default plugin;
@@ -0,0 +1,16 @@
1
+ {
2
+ "id": "clawchain-wallet",
3
+ "name": "ClawChain Wallet",
4
+ "description": "ClawChain 私有链钱包管理工具 - 支持创建钱包、导入钱包、余额查询、转账等功能",
5
+ "version": "1.0.0",
6
+ "configSchema": {
7
+ "type": "object",
8
+ "additionalProperties": false,
9
+ "properties": {
10
+ "walletsDir": {
11
+ "type": "string",
12
+ "description": "钱包存储目录路径(可选,默认为 ~/.clawchain/wallets)"
13
+ }
14
+ }
15
+ }
16
+ }