@tronscanteam/cli 1.0.0 → 1.0.1
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 +38 -11
- package/README_CN.md +38 -13
- package/package.json +1 -1
- package/src/api.js +16 -5
- package/src/commands.js +25 -17
- package/src/help.js +10 -7
- package/src/index.js +56 -1
package/README.md
CHANGED
|
@@ -6,7 +6,38 @@ A CLI tool built on [TronScan API](https://docs.tronscan.org/), providing 80+ su
|
|
|
6
6
|
|
|
7
7
|
Two ways to use: **`ts` in the terminal** (after global install) and **natural language in AI IDEs** ([Claude Code](https://claude.ai/code), [Cursor](https://cursor.com), VS Code Copilot, etc.).
|
|
8
8
|
|
|
9
|
-
## Install
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
### 1. Install from npm
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install -g @tronscanteam/cli
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
This registers the global command **`ts`** for use in any directory. Run `ts help` to see all commands.
|
|
18
|
+
|
|
19
|
+
**API Key**:
|
|
20
|
+
|
|
21
|
+
Get your API Key: https://docs.tronscan.org/zh/api/api-keys
|
|
22
|
+
|
|
23
|
+
**Method A: `ts setup`**
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
ts setup YOUR_API_KEY
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Method B: environment variable**
|
|
30
|
+
|
|
31
|
+
Persist it in your shell config, then `source` once. zsh example:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
echo 'export TRONSCAN_API_KEY="your-api-key"' >> ~/.zshrc
|
|
35
|
+
source ~/.zshrc
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
For bash, use `~/.bashrc` or `~/.bash_profile` instead of `~/.zshrc`.
|
|
39
|
+
|
|
40
|
+
### 2. Install from source (clone)
|
|
10
41
|
|
|
11
42
|
```bash
|
|
12
43
|
git clone https://github.com/sshnii/tronscan-cli.git
|
|
@@ -16,9 +47,7 @@ cp .env.example .env
|
|
|
16
47
|
# Edit .env and set TRONSCAN_API_KEY
|
|
17
48
|
```
|
|
18
49
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
Register **`ts`** on your machine (use either one):
|
|
50
|
+
Register **`ts`** on your machine:
|
|
22
51
|
|
|
23
52
|
```bash
|
|
24
53
|
npm link
|
|
@@ -26,13 +55,13 @@ npm link
|
|
|
26
55
|
npm install -g .
|
|
27
56
|
```
|
|
28
57
|
|
|
29
|
-
The CLI
|
|
58
|
+
The CLI reads `.env` from the **cloned project root** (next to `package.json`). After that, run `ts` from any working directory.
|
|
30
59
|
|
|
31
60
|
## Usage
|
|
32
61
|
|
|
33
62
|
### 1. In the terminal
|
|
34
63
|
|
|
35
|
-
After installing `ts` globally, run commands directly
|
|
64
|
+
After installing `ts` globally, run commands directly:
|
|
36
65
|
|
|
37
66
|
```bash
|
|
38
67
|
ts help # list all subcommands
|
|
@@ -48,7 +77,7 @@ ts security-account TXxx... # account risk check
|
|
|
48
77
|
|
|
49
78
|
### 2. In AI IDEs
|
|
50
79
|
|
|
51
|
-
|
|
80
|
+
To use with AI IDEs, we recommend installing from source (clone). Cloning downloads the full set of rule files (`CLAUDE.md`, `.cursorrules`, `.github/copilot-instructions.md`), which improve AI response accuracy. Run `ts setup` on first use to quickly configure your API Key.
|
|
52
81
|
|
|
53
82
|
Built-in rule files:
|
|
54
83
|
|
|
@@ -94,14 +123,12 @@ No need to memorize commands or API paths — the AI matches the best endpoint f
|
|
|
94
123
|
| Account | 11 | Balance, holdings, resources, approvals, votes, analysis |
|
|
95
124
|
| Super Representative | 4 | SR list, votes, chain parameters, proposals |
|
|
96
125
|
| Transaction | 10 | Transaction details, transfers (TRX/TRC20/TRC721/TRC1155) |
|
|
97
|
-
| Statistics |
|
|
98
|
-
| Contract |
|
|
126
|
+
| Statistics | 17 | TRX supply, transaction trends, active accounts, energy, DeFi TVL |
|
|
127
|
+
| Contract | 9 | Contract details, callers, energy consumption, daily analysis |
|
|
99
128
|
| Security | 6 | Account/token/URL/transaction risk detection, authorization check |
|
|
100
129
|
| Deep Analysis | 4 | Related accounts, fund flow, large transactions |
|
|
101
130
|
| Stablecoin | 11 | Holder distribution, top holders, mint/burn, liquidity pools |
|
|
102
131
|
|
|
103
|
-
Run `ts help` for the full command list.
|
|
104
|
-
|
|
105
132
|
## API Reference
|
|
106
133
|
|
|
107
134
|
See [api-reference.md](api-reference.md) for the complete API endpoint list.
|
package/README_CN.md
CHANGED
|
@@ -6,7 +6,38 @@
|
|
|
6
6
|
|
|
7
7
|
支持两种使用方式:**终端全局命令 `ts`** 和 **在 AI IDE 中用自然语言查询**(支持 [Claude Code](https://claude.ai/code)、[Cursor](https://cursor.com)、VS Code Copilot 等)。
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## 安装
|
|
10
|
+
|
|
11
|
+
### 一、通过 npm 全局安装
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install -g @tronscanteam/cli
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
安装后即可在任意目录使用全局命令 **`ts`**,输入 `ts help` 查看全部命令。
|
|
18
|
+
|
|
19
|
+
**配置 API Key**:
|
|
20
|
+
|
|
21
|
+
API Key 申请:https://docs.tronscan.org/zh/api/api-keys
|
|
22
|
+
|
|
23
|
+
**方式 A:`ts setup`**
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
ts setup YOUR_API_KEY
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**方式 B:环境变量**
|
|
30
|
+
|
|
31
|
+
长期生效:把密钥写进 shell 配置文件,保存后执行一次 `source`。zsh 示例:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
echo 'export TRONSCAN_API_KEY="你的密钥"' >> ~/.zshrc
|
|
35
|
+
source ~/.zshrc
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
使用 bash 时,将 `~/.zshrc` 换成 `~/.bashrc` 或 `~/.bash_profile`。
|
|
39
|
+
|
|
40
|
+
### 二、从源码克隆安装
|
|
10
41
|
|
|
11
42
|
```bash
|
|
12
43
|
git clone https://github.com/sshnii/tronscan-cli.git
|
|
@@ -16,9 +47,7 @@ cp .env.example .env
|
|
|
16
47
|
# 编辑 .env,设置 TRONSCAN_API_KEY
|
|
17
48
|
```
|
|
18
49
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
在本机注册全局命令 **`ts`**(任选其一):
|
|
50
|
+
在本机注册全局命令 **`ts`**:
|
|
22
51
|
|
|
23
52
|
```bash
|
|
24
53
|
npm link
|
|
@@ -26,13 +55,13 @@ npm link
|
|
|
26
55
|
npm install -g .
|
|
27
56
|
```
|
|
28
57
|
|
|
29
|
-
CLI
|
|
58
|
+
CLI 会从**克隆下来的项目根目录**(与 `package.json` 同级)读取 `.env`;配置好后在任意工作目录都可执行 `ts`。
|
|
30
59
|
|
|
31
60
|
## 使用方式
|
|
32
61
|
|
|
33
62
|
### 一、在终端中使用
|
|
34
63
|
|
|
35
|
-
全局安装 `ts`
|
|
64
|
+
全局安装 `ts` 后,在终端直接输入命令:
|
|
36
65
|
|
|
37
66
|
```bash
|
|
38
67
|
ts help # 查看所有子命令
|
|
@@ -48,9 +77,7 @@ ts security-account TXxx... # 账户风险检测
|
|
|
48
77
|
|
|
49
78
|
### 二、在 AI IDE 中使用
|
|
50
79
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
已内置规则文件:
|
|
80
|
+
若要在 AI IDE 中使用,建议优先通过从源码克隆的方式安装。克隆会下载完整的规则文件(`CLAUDE.md`、`.cursorrules`、`.github/copilot-instructions.md`),提升 AI 回复的准确性。首次使用运行 `ts setup` 即可快速完成 API Key 配置。
|
|
54
81
|
|
|
55
82
|
| AI IDE | 规则文件 |
|
|
56
83
|
|--------|----------|
|
|
@@ -94,14 +121,12 @@ AI:自动执行 ts tps 并返回结果
|
|
|
94
121
|
| 账户 | 11 | 余额、持仓、资源、授权、投票、分析 |
|
|
95
122
|
| 超级代表 | 4 | SR 列表、投票、链参数、提案 |
|
|
96
123
|
| 交易 | 10 | 交易详情、转账记录(TRX/TRC20/TRC721/TRC1155) |
|
|
97
|
-
| 统计 |
|
|
98
|
-
| 合约 |
|
|
124
|
+
| 统计 | 17 | TRX 供应、交易趋势、活跃账户、能量、DeFi TVL |
|
|
125
|
+
| 合约 | 9 | 合约详情、调用者、能量消耗、日度分析 |
|
|
99
126
|
| 安全 | 6 | 账户/代币/URL/交易风险检测、授权检查 |
|
|
100
127
|
| 深度分析 | 4 | 关联账户、资金流向、大额交易 |
|
|
101
128
|
| 稳定币 | 11 | 持仓分布、大户、增发/销毁、流动性池 |
|
|
102
129
|
|
|
103
|
-
输入 `ts help` 查看完整命令列表。
|
|
104
|
-
|
|
105
130
|
## API 参考
|
|
106
131
|
|
|
107
132
|
完整 API 接口列表见 [api-reference.md](api-reference.md)。
|
package/package.json
CHANGED
package/src/api.js
CHANGED
|
@@ -7,9 +7,9 @@ import { dirname } from 'path';
|
|
|
7
7
|
|
|
8
8
|
const __filename = fileURLToPath(import.meta.url);
|
|
9
9
|
const __dirname = dirname(__filename);
|
|
10
|
-
const PROJECT_ROOT = resolve(__dirname, '..');
|
|
10
|
+
export const PROJECT_ROOT = resolve(__dirname, '..');
|
|
11
11
|
|
|
12
|
-
export const VERSION = '1.0.
|
|
12
|
+
export const VERSION = '1.0.1';
|
|
13
13
|
const BASE_URL = 'https://apilist.tronscanapi.com';
|
|
14
14
|
|
|
15
15
|
let apiKey = process.env.TRONSCAN_API_KEY || '';
|
|
@@ -29,7 +29,8 @@ export function loadConfig() {
|
|
|
29
29
|
}
|
|
30
30
|
if (!apiKey) {
|
|
31
31
|
err('未找到 API Key');
|
|
32
|
-
warn('
|
|
32
|
+
warn('API Key 申请: https://tronscan.org/#/developer/api');
|
|
33
|
+
warn('运行 ts setup YOUR_API_KEY 快速配置');
|
|
33
34
|
process.exit(2);
|
|
34
35
|
}
|
|
35
36
|
}
|
|
@@ -82,7 +83,12 @@ export async function get(path) {
|
|
|
82
83
|
if (body) console.error(body);
|
|
83
84
|
process.exit(4);
|
|
84
85
|
}
|
|
85
|
-
|
|
86
|
+
const text = await res.text();
|
|
87
|
+
try {
|
|
88
|
+
return JSON.parse(text);
|
|
89
|
+
} catch {
|
|
90
|
+
throw new Error(`API 返回非 JSON: ${text.slice(0, 200)}`);
|
|
91
|
+
}
|
|
86
92
|
}
|
|
87
93
|
|
|
88
94
|
export async function post(path, body) {
|
|
@@ -108,7 +114,12 @@ export async function post(path, body) {
|
|
|
108
114
|
if (text) console.error(text);
|
|
109
115
|
process.exit(4);
|
|
110
116
|
}
|
|
111
|
-
|
|
117
|
+
const text = await res.text();
|
|
118
|
+
try {
|
|
119
|
+
return JSON.parse(text);
|
|
120
|
+
} catch {
|
|
121
|
+
throw new Error(`API 返回非 JSON: ${text.slice(0, 200)}`);
|
|
122
|
+
}
|
|
112
123
|
}
|
|
113
124
|
|
|
114
125
|
// ============ Output ============
|
package/src/commands.js
CHANGED
|
@@ -54,7 +54,7 @@ export const commands = {
|
|
|
54
54
|
},
|
|
55
55
|
'account-votes': {
|
|
56
56
|
usage: 'ts account-votes <address>', desc: '投票记录',
|
|
57
|
-
run: (a) => get(`/api/vote?
|
|
57
|
+
run: (a) => get(`/api/vote?voter=${require(a, 0, 'address', 'ts account-votes <address>')}`)
|
|
58
58
|
},
|
|
59
59
|
'account-analysis': {
|
|
60
60
|
usage: 'ts account-analysis <address>', desc: '日度分析',
|
|
@@ -360,8 +360,12 @@ export const commands = {
|
|
|
360
360
|
run: () => get('/api/tokenTvc')
|
|
361
361
|
},
|
|
362
362
|
'token-analysis': {
|
|
363
|
-
usage: 'ts token-analysis', desc: '代币交易分析',
|
|
364
|
-
run: () =>
|
|
363
|
+
usage: 'ts token-analysis <contract|symbol>', desc: '代币交易分析',
|
|
364
|
+
run: async (a) => {
|
|
365
|
+
require(a, 0, 'contract|symbol', 'ts token-analysis <contract|symbol>');
|
|
366
|
+
const contract = await resolveAndLog(a[0], resolveContract);
|
|
367
|
+
return get(`/api/token/analysis?token=${contract}`);
|
|
368
|
+
}
|
|
365
369
|
},
|
|
366
370
|
'token-transfer-analysis': {
|
|
367
371
|
usage: 'ts token-transfer-analysis', desc: '代币转账分析',
|
|
@@ -383,8 +387,12 @@ export const commands = {
|
|
|
383
387
|
run: (a) => get(`/api/deep/account/token/bigAmount?address=${require(a, 0, 'address', 'ts deep-big-tx <address>')}`)
|
|
384
388
|
},
|
|
385
389
|
'deep-token-transfer': {
|
|
386
|
-
usage: 'ts deep-token-transfer <address>', desc: '代币转账次数',
|
|
387
|
-
run: (a) =>
|
|
390
|
+
usage: 'ts deep-token-transfer <address> <contract>', desc: '代币转账次数',
|
|
391
|
+
run: (a) => {
|
|
392
|
+
require(a, 0, 'address', 'ts deep-token-transfer <address> <contract>');
|
|
393
|
+
require(a, 1, 'contract', 'ts deep-token-transfer <address> <contract>');
|
|
394
|
+
return get(`/api/deep/account/holderToken/basicInfo/trc20/transfer?accountAddress=${a[0]}&tokenAddress=${a[1]}`);
|
|
395
|
+
}
|
|
388
396
|
},
|
|
389
397
|
|
|
390
398
|
// --- 稳定币 ---
|
|
@@ -402,32 +410,32 @@ export const commands = {
|
|
|
402
410
|
run: () => get('/api/stableCoin/holder/top')
|
|
403
411
|
},
|
|
404
412
|
'stable-big-tx': {
|
|
405
|
-
usage: 'ts stable-big-tx', desc: '大额交易',
|
|
406
|
-
run: () => get(
|
|
413
|
+
usage: 'ts stable-big-tx [types]', desc: '大额交易 (types: 1=USDT 2=USDJ 3=TUSD 4=USDC)',
|
|
414
|
+
run: (a, o) => get(`/api/deep/stableCoin/bigAmount?types=${a[0] || '1'}&start=${o.start}&limit=${o.limit}`)
|
|
407
415
|
},
|
|
408
416
|
'stable-events': {
|
|
409
|
-
usage: 'ts stable-events', desc: '增发/销毁/黑名单事件',
|
|
410
|
-
run: () => get(
|
|
417
|
+
usage: 'ts stable-events [--sort 0|1] [--start N] [--limit N]', desc: '增发/销毁/黑名单事件 (sort: 0=asc 1=desc)',
|
|
418
|
+
run: (a, o) => get(`/api/deep/stableCoin/totalSupply/keyEvents?direction=1&sort=${o.sort || '1'}&start=${o.start}&limit=${o.limit}`)
|
|
411
419
|
},
|
|
412
420
|
'stable-dist': {
|
|
413
|
-
usage: 'ts stable-dist', desc: '交易所/DeFi 分布',
|
|
414
|
-
run: () => get(
|
|
421
|
+
usage: 'ts stable-dist <contract>', desc: '交易所/DeFi 分布',
|
|
422
|
+
run: (a) => get(`/api/stableCoin/distribution?token=${require(a, 0, 'contract', 'ts stable-dist <contract> (如 USDT: TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t)')}`)
|
|
415
423
|
},
|
|
416
424
|
'stable-liquidity': {
|
|
417
425
|
usage: 'ts stable-liquidity', desc: '流动性操作记录',
|
|
418
426
|
run: () => get('/api/deep/stableCoin/liquidity/transaction')
|
|
419
427
|
},
|
|
420
428
|
'stable-pool': {
|
|
421
|
-
usage: 'ts stable-pool', desc: '池子概览(TVL)',
|
|
422
|
-
run: () => get(
|
|
429
|
+
usage: 'ts stable-pool <pool_address>', desc: '池子概览(TVL)',
|
|
430
|
+
run: (a) => get(`/api/stableCoin/pool/overview?pool=${require(a, 0, 'pool_address', 'ts stable-pool <pool_address>')}`)
|
|
423
431
|
},
|
|
424
432
|
'stable-pool-trend': {
|
|
425
|
-
usage: 'ts stable-pool-trend', desc: '池子趋势',
|
|
426
|
-
run: () => get(
|
|
433
|
+
usage: 'ts stable-pool-trend <pool_address>', desc: '池子趋势',
|
|
434
|
+
run: (a) => get(`/api/stableCoin/pool/trend?pool=${require(a, 0, 'pool_address', 'ts stable-pool-trend <pool_address>')}`)
|
|
427
435
|
},
|
|
428
436
|
'stable-pool-change': {
|
|
429
|
-
usage: 'ts stable-pool-change', desc: '池子历史变化',
|
|
430
|
-
run: () => get(
|
|
437
|
+
usage: 'ts stable-pool-change <pool_address>', desc: '池子历史变化',
|
|
438
|
+
run: (a) => get(`/api/stableCoin/pool/change?pool=${require(a, 0, 'pool_address', 'ts stable-pool-change <pool_address>')}`)
|
|
431
439
|
},
|
|
432
440
|
'stable-tvl': {
|
|
433
441
|
usage: 'ts stable-tvl', desc: '稳定币 TVL 分布',
|
package/src/help.js
CHANGED
|
@@ -17,6 +17,9 @@ ${B('全局选项:')}
|
|
|
17
17
|
--help, -h 显示命令帮助
|
|
18
18
|
--version, -V 显示版本号
|
|
19
19
|
|
|
20
|
+
配置:
|
|
21
|
+
ts setup [api-key] 配置 API Key(首次使用必须)
|
|
22
|
+
|
|
20
23
|
代币:
|
|
21
24
|
ts token <contract|symbol> TRC20 代币详情(支持 USDT 等符号)
|
|
22
25
|
ts token-trc10 <id|symbol> TRC10 代币详情
|
|
@@ -85,7 +88,7 @@ ${B('全局选项:')}
|
|
|
85
88
|
ts bandwidth-daily 每日带宽消耗
|
|
86
89
|
ts trigger-stats 合约调用分布
|
|
87
90
|
ts token-tvc 代币链上价值(TVC)
|
|
88
|
-
ts token-analysis
|
|
91
|
+
ts token-analysis <contract|symbol> 代币交易分析
|
|
89
92
|
ts token-transfer-analysis 代币转账分析
|
|
90
93
|
|
|
91
94
|
合约:
|
|
@@ -112,19 +115,19 @@ ${B('全局选项:')}
|
|
|
112
115
|
ts deep-related <addr> 关联账户
|
|
113
116
|
ts deep-flow <addr> 资金流向
|
|
114
117
|
ts deep-big-tx <addr> 大额交易
|
|
115
|
-
ts deep-token-transfer <addr>
|
|
118
|
+
ts deep-token-transfer <addr> <contract> 代币转账次数
|
|
116
119
|
|
|
117
120
|
稳定币:
|
|
118
121
|
ts stable-holders 持仓分布概览
|
|
119
122
|
ts stable-change 持有者变化趋势
|
|
120
123
|
ts stable-top 大户排行
|
|
121
|
-
ts stable-big-tx
|
|
124
|
+
ts stable-big-tx [types] 大额交易 (1=USDT 2=USDJ 3=TUSD 4=USDC)
|
|
122
125
|
ts stable-events 增发/销毁/黑名单事件
|
|
123
|
-
ts stable-dist
|
|
126
|
+
ts stable-dist <contract> 交易所/DeFi 分布
|
|
124
127
|
ts stable-liquidity 流动性操作记录
|
|
125
|
-
ts stable-pool
|
|
126
|
-
ts stable-pool-trend
|
|
127
|
-
ts stable-pool-change
|
|
128
|
+
ts stable-pool <pool_address> 池子概览(TVL)
|
|
129
|
+
ts stable-pool-trend <pool_address> 池子趋势
|
|
130
|
+
ts stable-pool-change <pool_address> 池子历史变化
|
|
128
131
|
ts stable-tvl 稳定币 TVL 分布
|
|
129
132
|
`);
|
|
130
133
|
}
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { resolve } from 'path';
|
|
4
|
+
import { existsSync, readFileSync, writeFileSync, copyFileSync } from 'fs';
|
|
5
|
+
import { loadConfig, output, err, warn, VERSION, PROJECT_ROOT } from './api.js';
|
|
4
6
|
import { commands } from './commands.js';
|
|
5
7
|
import { printHelp, printCommandHelp } from './help.js';
|
|
6
8
|
|
|
@@ -44,6 +46,59 @@ while (i < rest.length) {
|
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
|
|
49
|
+
// ============ Setup (before loadConfig) ============
|
|
50
|
+
|
|
51
|
+
if (cmd === 'setup') {
|
|
52
|
+
const envPath = resolve(PROJECT_ROOT, '.env');
|
|
53
|
+
const examplePath = resolve(PROJECT_ROOT, '.env.example');
|
|
54
|
+
const isTTY = process.stderr.isTTY ?? false;
|
|
55
|
+
const green = (s) => (isTTY ? `\x1b[32m${s}\x1b[0m` : s);
|
|
56
|
+
const bold = (s) => (isTTY ? `\x1b[1m${s}\x1b[0m` : s);
|
|
57
|
+
const dim = (s) => (isTTY ? `\x1b[2m${s}\x1b[0m` : s);
|
|
58
|
+
|
|
59
|
+
const inputKey = positional[0];
|
|
60
|
+
|
|
61
|
+
if (inputKey) {
|
|
62
|
+
// 校验:过滤明显无效的输入
|
|
63
|
+
if (/[<>]/.test(inputKey) || inputKey === 'your-api-key' || inputKey === 'your_api_key_here') {
|
|
64
|
+
err('请替换为你的真实 API Key');
|
|
65
|
+
warn('API Key 申请: https://tronscan.org/#/developer/api');
|
|
66
|
+
process.exit(2);
|
|
67
|
+
}
|
|
68
|
+
// 直接写入 API Key
|
|
69
|
+
writeFileSync(envPath, `TRONSCAN_API_KEY=${inputKey}\n`);
|
|
70
|
+
console.log(green('✓ API Key 已写入 .env'));
|
|
71
|
+
console.log(dim(` 路径: ${envPath}`));
|
|
72
|
+
console.log(`\n 现在可以使用 ${bold('ts')} 命令了,试试: ${bold('ts tps')}`);
|
|
73
|
+
process.exit(0);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 检查现有配置
|
|
77
|
+
if (existsSync(envPath)) {
|
|
78
|
+
const content = readFileSync(envPath, 'utf-8');
|
|
79
|
+
const match = content.match(/^\s*TRONSCAN_API_KEY\s*=\s*(.+?)\s*$/m);
|
|
80
|
+
const key = match?.[1]?.replace(/^["']|["']$/g, '');
|
|
81
|
+
if (key && key !== 'your_api_key_here') {
|
|
82
|
+
console.log(green('✓ API Key 已配置'));
|
|
83
|
+
console.log(dim(` 路径: ${envPath}`));
|
|
84
|
+
console.log(dim(` Key: ${key.slice(0, 8)}...${key.slice(-4)}`));
|
|
85
|
+
process.exit(0);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// 未配置,引导用户
|
|
90
|
+
if (!existsSync(envPath) && existsSync(examplePath)) {
|
|
91
|
+
copyFileSync(examplePath, envPath);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
console.log(bold('TronScan CLI 配置向导\n'));
|
|
95
|
+
console.log(` 1. 申请 API Key: ${bold('https://tronscan.org/#/developer/api')}`);
|
|
96
|
+
console.log(` 2. 运行: ${bold('ts setup <your-api-key>')}`);
|
|
97
|
+
console.log(` 或手动编辑: ${dim(envPath)}`);
|
|
98
|
+
console.log(`\n 也可设置环境变量: ${bold('export TRONSCAN_API_KEY=<your-api-key>')}`);
|
|
99
|
+
process.exit(0);
|
|
100
|
+
}
|
|
101
|
+
|
|
47
102
|
// ============ Dispatch ============
|
|
48
103
|
|
|
49
104
|
const command = commands[cmd];
|