@tronscanteam/cli 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.
- package/.env.example +1 -0
- package/README.md +111 -0
- package/README_CN.md +111 -0
- package/api-reference.md +177 -0
- package/package.json +38 -0
- package/src/api.js +152 -0
- package/src/commands.js +443 -0
- package/src/help.js +140 -0
- package/src/index.js +71 -0
package/.env.example
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
TRONSCAN_API_KEY=your_api_key_here
|
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# TronScan CLI
|
|
2
|
+
|
|
3
|
+
[中文文档](README_CN.md)
|
|
4
|
+
|
|
5
|
+
A CLI tool built on [TronScan API](https://docs.tronscan.org/), providing 80+ subcommands covering tokens, search, blocks, accounts, governance, transactions, statistics, contracts, security, deep analysis, stablecoins, and more.
|
|
6
|
+
|
|
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
|
+
|
|
9
|
+
## Install (global `ts` command)
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
git clone https://github.com/sshnii/tronscan-cli.git
|
|
13
|
+
cd tronscan-cli
|
|
14
|
+
npm install
|
|
15
|
+
cp .env.example .env
|
|
16
|
+
# Edit .env and set TRONSCAN_API_KEY
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Get your API Key: https://docs.tronscan.org/zh/api/api-keys
|
|
20
|
+
|
|
21
|
+
Register **`ts`** on your machine (use either one):
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm link
|
|
25
|
+
# or
|
|
26
|
+
npm install -g .
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The CLI loads `.env` from the **cloned project root** (same folder as `package.json`). Keep your API Key there; you can run `ts` from any working directory.
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
### 1. In the terminal
|
|
34
|
+
|
|
35
|
+
After installing `ts` globally, run commands directly (`ts help` lists all subcommands):
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
ts help # list all subcommands
|
|
39
|
+
ts token usdt # token info
|
|
40
|
+
ts search usdt # search
|
|
41
|
+
ts block # latest block
|
|
42
|
+
ts tps # current TPS
|
|
43
|
+
ts account TXxx... # account details
|
|
44
|
+
ts tx af949... # transaction by hash
|
|
45
|
+
ts transfer-trc20 TXxx... # TRC20 transfers
|
|
46
|
+
ts security-account TXxx... # account risk check
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 2. In AI IDEs
|
|
50
|
+
|
|
51
|
+
Open this repo as your working directory and describe what you need in natural language. The AI reads the rule files, infers intent, picks the right API, and interprets the response.
|
|
52
|
+
|
|
53
|
+
Built-in rule files:
|
|
54
|
+
|
|
55
|
+
| AI IDE | Rule File |
|
|
56
|
+
|--------|-----------|
|
|
57
|
+
| Claude Code | `CLAUDE.md` |
|
|
58
|
+
| Cursor | `.cursorrules` |
|
|
59
|
+
| VS Code Copilot | `.github/copilot-instructions.md` |
|
|
60
|
+
|
|
61
|
+
Example using Claude Code:
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
You: Look up USDT token info
|
|
65
|
+
AI: Runs ts token usdt and summarizes key fields (price, supply, holders, etc.)
|
|
66
|
+
|
|
67
|
+
You: Show account details for TXxx...
|
|
68
|
+
AI: Runs ts account TXxx... and interprets balance, resources, and related fields
|
|
69
|
+
|
|
70
|
+
You: What's the TRON network overview?
|
|
71
|
+
AI: Runs ts overview and summarizes the bundled network stats
|
|
72
|
+
|
|
73
|
+
You: What's the latest block?
|
|
74
|
+
AI: Runs ts block and summarizes the latest block (or height and key fields)
|
|
75
|
+
|
|
76
|
+
You: What's the current TPS?
|
|
77
|
+
AI: Runs ts tps and returns the result
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
No need to memorize commands or API paths — the AI matches the best endpoint from 80+ APIs in `api-reference.md`.
|
|
81
|
+
|
|
82
|
+
## Dependencies
|
|
83
|
+
|
|
84
|
+
- [Node.js](https://nodejs.org/) >= 18
|
|
85
|
+
|
|
86
|
+
## Command Categories
|
|
87
|
+
|
|
88
|
+
| Category | Count | Description |
|
|
89
|
+
|----------|-------|-------------|
|
|
90
|
+
| Token | 7 | Token details, holders, price, list, distribution |
|
|
91
|
+
| Search | 2 | Search, trending tokens |
|
|
92
|
+
| Overview | 3 | TPS, TRON network overview, nodes |
|
|
93
|
+
| Block | 1 | Latest or specific block |
|
|
94
|
+
| Account | 11 | Balance, holdings, resources, approvals, votes, analysis |
|
|
95
|
+
| Super Representative | 4 | SR list, votes, chain parameters, proposals |
|
|
96
|
+
| Transaction | 10 | Transaction details, transfers (TRX/TRC20/TRC721/TRC1155) |
|
|
97
|
+
| Statistics | 19 | TRX supply, transaction trends, active accounts, energy, DeFi TVL |
|
|
98
|
+
| Contract | 10 | Contract details, callers, energy consumption, daily analysis |
|
|
99
|
+
| Security | 6 | Account/token/URL/transaction risk detection, authorization check |
|
|
100
|
+
| Deep Analysis | 4 | Related accounts, fund flow, large transactions |
|
|
101
|
+
| Stablecoin | 11 | Holder distribution, top holders, mint/burn, liquidity pools |
|
|
102
|
+
|
|
103
|
+
Run `ts help` for the full command list.
|
|
104
|
+
|
|
105
|
+
## API Reference
|
|
106
|
+
|
|
107
|
+
See [api-reference.md](api-reference.md) for the complete API endpoint list.
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
MIT
|
package/README_CN.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# TronScan CLI
|
|
2
|
+
|
|
3
|
+
[English](README.md)
|
|
4
|
+
|
|
5
|
+
基于 [TronScan API](https://docs.tronscan.org/) 的命令行工具,80+ 子命令覆盖代币、搜索、区块、账户、治理、交易、统计、合约、安全、深度分析、稳定币等场景。
|
|
6
|
+
|
|
7
|
+
支持两种使用方式:**终端全局命令 `ts`** 和 **在 AI IDE 中用自然语言查询**(支持 [Claude Code](https://claude.ai/code)、[Cursor](https://cursor.com)、VS Code Copilot 等)。
|
|
8
|
+
|
|
9
|
+
## 安装(全局命令 `ts`)
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
git clone https://github.com/sshnii/tronscan-cli.git
|
|
13
|
+
cd tronscan-cli
|
|
14
|
+
npm install
|
|
15
|
+
cp .env.example .env
|
|
16
|
+
# 编辑 .env,设置 TRONSCAN_API_KEY
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
API Key 申请:https://docs.tronscan.org/zh/api/api-keys
|
|
20
|
+
|
|
21
|
+
在本机注册全局命令 **`ts`**(任选其一):
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm link
|
|
25
|
+
# 或
|
|
26
|
+
npm install -g .
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
CLI 会从**你克隆下来的项目根目录**(与 `package.json` 同级)读取 `.env`。请在该目录配置好 API Key;之后在任意工作目录都可以直接执行 `ts`。
|
|
30
|
+
|
|
31
|
+
## 使用方式
|
|
32
|
+
|
|
33
|
+
### 一、在终端中使用
|
|
34
|
+
|
|
35
|
+
全局安装 `ts` 后,在终端直接输入命令(`ts help` 可查看全部子命令):
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
ts help # 查看所有子命令
|
|
39
|
+
ts token usdt # 代币信息
|
|
40
|
+
ts search usdt # 搜索
|
|
41
|
+
ts block # 最新区块
|
|
42
|
+
ts tps # 当前 TPS
|
|
43
|
+
ts account TXxx... # 账户详情
|
|
44
|
+
ts tx af949... # 按交易哈希查询
|
|
45
|
+
ts transfer-trc20 TXxx... # TRC20 转账记录
|
|
46
|
+
ts security-account TXxx... # 账户风险检测
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 二、在 AI IDE 中使用
|
|
50
|
+
|
|
51
|
+
将本项目作为工作目录打开,用自然语言描述需求即可;AI 会读取规则文件,识别意图、选择接口并解读返回结果。
|
|
52
|
+
|
|
53
|
+
已内置规则文件:
|
|
54
|
+
|
|
55
|
+
| AI IDE | 规则文件 |
|
|
56
|
+
|--------|----------|
|
|
57
|
+
| Claude Code | `CLAUDE.md` |
|
|
58
|
+
| Cursor | `.cursorrules` |
|
|
59
|
+
| VS Code Copilot | `.github/copilot-instructions.md` |
|
|
60
|
+
|
|
61
|
+
以 Claude Code 为例,你只需要用自然语言描述需求:
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
你:查一下 USDT 代币信息
|
|
65
|
+
AI:自动执行 ts token usdt 并解读价格、供应、持币地址等关键字段
|
|
66
|
+
|
|
67
|
+
你:查一下这个地址的账户信息 TXxx...
|
|
68
|
+
AI:自动执行 ts account TXxx... 并解读余额、资源等相关字段
|
|
69
|
+
|
|
70
|
+
你:TRON 网络概况怎么样
|
|
71
|
+
AI:自动执行 ts overview 并汇总网络综合数据
|
|
72
|
+
|
|
73
|
+
你:最新区块是什么
|
|
74
|
+
AI:自动执行 ts block 并解读最新区块(或高度与关键字段)
|
|
75
|
+
|
|
76
|
+
你:当前 TPS 多少
|
|
77
|
+
AI:自动执行 ts tps 并返回结果
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
无需记住任何命令和 API 路径,AI 会根据 `api-reference.md` 中的 80+ 接口自动匹配最合适的调用方式。
|
|
81
|
+
|
|
82
|
+
## 依赖
|
|
83
|
+
|
|
84
|
+
- [Node.js](https://nodejs.org/) >= 18
|
|
85
|
+
|
|
86
|
+
## 命令分类
|
|
87
|
+
|
|
88
|
+
| 分类 | 命令数 | 说明 |
|
|
89
|
+
|------|--------|------|
|
|
90
|
+
| 代币 | 7 | 代币详情、持有者、价格、列表、持仓分布 |
|
|
91
|
+
| 搜索 | 2 | 搜索、热搜代币 |
|
|
92
|
+
| 概览 | 3 | TPS、TRON 网络概览、节点 |
|
|
93
|
+
| 区块 | 1 | 最新或指定区块 |
|
|
94
|
+
| 账户 | 11 | 余额、持仓、资源、授权、投票、分析 |
|
|
95
|
+
| 超级代表 | 4 | SR 列表、投票、链参数、提案 |
|
|
96
|
+
| 交易 | 10 | 交易详情、转账记录(TRX/TRC20/TRC721/TRC1155) |
|
|
97
|
+
| 统计 | 19 | TRX 供应、交易趋势、活跃账户、能量、DeFi TVL |
|
|
98
|
+
| 合约 | 10 | 合约详情、调用者、能量消耗、日度分析 |
|
|
99
|
+
| 安全 | 6 | 账户/代币/URL/交易风险检测、授权检查 |
|
|
100
|
+
| 深度分析 | 4 | 关联账户、资金流向、大额交易 |
|
|
101
|
+
| 稳定币 | 11 | 持仓分布、大户、增发/销毁、流动性池 |
|
|
102
|
+
|
|
103
|
+
输入 `ts help` 查看完整命令列表。
|
|
104
|
+
|
|
105
|
+
## API 参考
|
|
106
|
+
|
|
107
|
+
完整 API 接口列表见 [api-reference.md](api-reference.md)。
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
MIT
|
package/api-reference.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# TronScan API 速查表
|
|
2
|
+
|
|
3
|
+
Base URL: `https://apilist.tronscanapi.com`
|
|
4
|
+
认证 Header: `TRON-PRO-API-KEY: <key>`
|
|
5
|
+
通用分页: `start=0&limit=20`(start+limit ≤ 10000)
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 账户
|
|
10
|
+
|
|
11
|
+
| 接口 | 用途 | 关键参数 |
|
|
12
|
+
|------|------|----------|
|
|
13
|
+
| `GET /api/accountv2?address=` | 账户详情(余额、资源、质押) | `address` |
|
|
14
|
+
| `GET /api/account/list` | 账户列表排行 | `start`, `limit`, `sort=-balance` |
|
|
15
|
+
| `GET /api/account/tokens` | 账户持仓代币 | `address`, `start`, `limit` |
|
|
16
|
+
| `GET /api/account/resourcev2` | Stake 2.0 资源(带宽/能量) | `address` |
|
|
17
|
+
| `GET /api/account/resource` | Stake 1.0 资源 | `address` |
|
|
18
|
+
| `GET /api/account/approve/list` | 代币授权列表 | `address`, `start`, `limit` |
|
|
19
|
+
| `GET /api/account/approve/change` | 授权变更历史 | `address` |
|
|
20
|
+
| `GET /api/account/analysis` | 账户日度分析(余额、转账、能量) | `address` |
|
|
21
|
+
| `GET /api/account/token_asset_overview` | 钱包持仓总览(含估值) | `address` |
|
|
22
|
+
| `GET /api/vote` | 投票记录 | `address` |
|
|
23
|
+
| `GET /api/participate_project` | 参与项目 | `address` |
|
|
24
|
+
| `GET /api/multiple/chain/query` | 多链地址查询 | `address` |
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 交易 & 转账
|
|
29
|
+
|
|
30
|
+
| 接口 | 用途 | 关键参数 |
|
|
31
|
+
|------|------|----------|
|
|
32
|
+
| `GET /api/transaction` | 交易列表 | `start`, `limit`, `fromAddress`, `toAddress`, `block`, `start_timestamp`, `end_timestamp` |
|
|
33
|
+
| `GET /api/transaction-info?hash=` | 交易详情(按哈希) | `hash` |
|
|
34
|
+
| `GET /api/transfer` | TRX & TRC10 转账记录 | `address`, `fromAddress`, `toAddress`, `tokens`, `start`, `limit` |
|
|
35
|
+
| `GET /api/token_trc20/transfers` | TRC20/TRC721 转账 | `relatedAddress`, `contract_address`, `fromAddress`, `toAddress`, `start`, `limit`, `start_timestamp`, `end_timestamp` |
|
|
36
|
+
| `GET /api/token_trc1155/transfers` | TRC1155 转账 | `relatedAddress`, `contract_address`, `start`, `limit` |
|
|
37
|
+
| `GET /api/internal-transaction` | 内部交易 | `address`, `contract`, `block`, `start`, `limit` |
|
|
38
|
+
| `GET /api/token_trc20/transfers-with-status` | TRC20 转账(带状态) | `address`, `trc20Id`, `direction`, `start`, `limit` |
|
|
39
|
+
| `GET /api/exchange/transaction` | 交易所交易 | `exchangeID`, `address`, `start`, `limit` |
|
|
40
|
+
| `GET /api/transaction/statistics` | 交易统计 | - |
|
|
41
|
+
| `GET /api/transfer/statistics` | 转账分布统计 | - |
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## 区块
|
|
46
|
+
|
|
47
|
+
| 接口 | 用途 | 关键参数 |
|
|
48
|
+
|------|------|----------|
|
|
49
|
+
| `GET /api/block` | 区块列表/详情 | `start`, `limit`, `producer`, `sort=-number`, `start_timestamp`, `end_timestamp` |
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## 代币
|
|
54
|
+
|
|
55
|
+
| 接口 | 用途 | 关键参数 |
|
|
56
|
+
|------|------|----------|
|
|
57
|
+
| `GET /api/tokens/overview` | 已索引代币列表/排行(CLI: `ts token-list`) | `start`, `limit`, `filter` |
|
|
58
|
+
| `GET /api/token_trc20` | TRC20/721/1155 代币详情 | `contract` |
|
|
59
|
+
| `GET /api/token` | TRC10 代币详情 | `id` |
|
|
60
|
+
| `GET /api/token_trc20/holders` | TRC20 持有者列表 | `contract_address`, `start`, `limit` |
|
|
61
|
+
| `GET /api/tokenholders` | TRC10 持有者列表 | `token`, `start`, `limit` |
|
|
62
|
+
| `GET /api/tokens/position-distribution` | 代币持仓分布 | `token` |
|
|
63
|
+
| `GET /api/token/price` | 代币价格 | `token` |
|
|
64
|
+
| `GET /api/trc721/transfers` | TRC721 转账记录 | `contract`, `tokenId` |
|
|
65
|
+
| `GET /api/token_trc20/totalSupply` | TRC20 流通量 | `contract` |
|
|
66
|
+
| `GET /api/trc721/token` | TRC721 NFT 详情 | `contract` |
|
|
67
|
+
| `GET /api/trc1155/inventory` | TRC1155 库存 | `contract` |
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## 合约
|
|
72
|
+
|
|
73
|
+
| 接口 | 用途 | 关键参数 |
|
|
74
|
+
|------|------|----------|
|
|
75
|
+
| `GET /api/contracts` | 合约列表 | `search`, `sort`, `start`, `limit`, `verified-only`, `open-source-only` |
|
|
76
|
+
| `GET /api/contract` | 合约详情 | `contract` |
|
|
77
|
+
| `POST /api/contracts/smart-contract-triggers-batch` | 合约事件 | `contractAddress`, `hashList`, `term`, `limit` |
|
|
78
|
+
| `GET /api/onecontractenergystatistic` | 合约能量消耗 | `address` |
|
|
79
|
+
| `GET /api/contracts/top_call` | 合约调用者排行 | `contract_address` |
|
|
80
|
+
| `GET /api/onecontractcallerstatistic` | 每日独立调用者 | `address`, `start_timestamp`, `end_timestamp` |
|
|
81
|
+
| `GET /api/onecontracttriggerstatistic` | 每日调用次数 | `address`, `start_timestamp`, `end_timestamp` |
|
|
82
|
+
| `GET /api/contract/analysis` | 合约日度分析 | `address`, `type`(0-5), `start_timestamp`, `end_timestamp` |
|
|
83
|
+
| `GET /api/onecontractcallers` | 所有调用者列表 | `address`, `day`, `start`, `limit` |
|
|
84
|
+
| `GET /api/contracts/trigger` | 合约触发交易 | `start`, `limit`, `start_timestamp`, `end_timestamp` |
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## 超级代表 & 治理
|
|
89
|
+
|
|
90
|
+
| 接口 | 用途 | 关键参数 |
|
|
91
|
+
|------|------|----------|
|
|
92
|
+
| `GET /api/pagewitness` | SR 列表 | `witnesstype`(0=SR,1=partner,3=candidate) |
|
|
93
|
+
| `GET /api/account/votes` | 账户投票记录 | `address` |
|
|
94
|
+
| `GET /api/vote/witness` | SR 当前投票详情 | `address` |
|
|
95
|
+
| `GET /api/chainparameters` | 链参数列表 | - |
|
|
96
|
+
| `GET /api/proposal` | 提案信息 | `id`, `start`, `limit`, `address` |
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## 安全检测
|
|
101
|
+
|
|
102
|
+
| 接口 | 用途 | 关键参数 |
|
|
103
|
+
|------|------|----------|
|
|
104
|
+
| `GET /api/security/account/data` | 账户风险检测 | `address` |
|
|
105
|
+
| `GET /api/security/token/data` | 代币安全检测 | `address` |
|
|
106
|
+
| `GET /api/security/url/data` | URL 钓鱼检测 | `url` |
|
|
107
|
+
| `GET /api/security/transaction/data` | 交易风险检测 | `hashes` |
|
|
108
|
+
| `GET /api/security/sign/data` | 多签配置检查 | `address` |
|
|
109
|
+
| `GET /api/security/auth/data` | 授权风险检查 | `address` |
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## 网络概览 & 搜索
|
|
114
|
+
|
|
115
|
+
| 接口 | 用途 | 关键参数 |
|
|
116
|
+
|------|------|----------|
|
|
117
|
+
| `GET /api/system/homepage-bundle` | TRON 网络概览(CLI: `ts overview`) | - |
|
|
118
|
+
| `GET /api/search/v2` | 全局搜索 | `term`, `type`(token/address/contract/transaction/block), `start`, `limit` |
|
|
119
|
+
| `GET /api/search/bar` | 热门搜索代币 | - |
|
|
120
|
+
| `GET /api/search/hot` | 热搜排行 | - |
|
|
121
|
+
| `GET /api/system/tps` | 当前 TPS | - |
|
|
122
|
+
| `GET /api/nodemap` | 全网节点信息 | - |
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## 链上统计
|
|
127
|
+
|
|
128
|
+
| 接口 | 用途 | 关键参数 |
|
|
129
|
+
|------|------|----------|
|
|
130
|
+
| `GET /api/funds` | TRX 供应量/销毁 | - |
|
|
131
|
+
| `GET /api/turnover` | TRX 发行与销毁分析 | - |
|
|
132
|
+
| `GET /api/trx/volume` | TRX 历史价格和交易量 | - |
|
|
133
|
+
| `GET /api/overview/dailytransactionnum` | 每日交易数趋势 | - |
|
|
134
|
+
| `GET /api/overview/transactionnum` | 累计交易数 | - |
|
|
135
|
+
| `GET /api/account/active_statistic` | 每日活跃账户 | - |
|
|
136
|
+
| `GET /api/overview/dailyaccounts` | 每日新增账户 | - |
|
|
137
|
+
| `GET /api/energydailystatistic` | 每日能量消耗 | - |
|
|
138
|
+
| `GET /api/energystatistic` | 能量消耗分布 | - |
|
|
139
|
+
| `GET /api/acquisition_cost_statistic` | 能量/带宽获取成本 | - |
|
|
140
|
+
| `GET /api/netstatistic` | 每日带宽消耗 | - |
|
|
141
|
+
| `GET /api/triggeramountstatistic` | 合约调用分布 | - |
|
|
142
|
+
| `GET /api/tokenTvc` | 代币链上价值(TVC) | - |
|
|
143
|
+
| `GET /api/token/analysis` | 代币交易分析 | - |
|
|
144
|
+
| `GET /api/tokenTransfer/analysis` | 代币转账分析 | - |
|
|
145
|
+
| `GET /api/overview/dailyavgblockSize` | 平均区块大小 | - |
|
|
146
|
+
| `GET /api/overview/totalblockchainsize` | 区块链总大小 | - |
|
|
147
|
+
| `GET /api/top10` | Top 10 排行 | - |
|
|
148
|
+
| `GET /api/defiTvl` | DeFi TVL | - |
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## 深度分析
|
|
153
|
+
|
|
154
|
+
| 接口 | 用途 | 关键参数 |
|
|
155
|
+
|------|------|----------|
|
|
156
|
+
| `GET /api/deep/account/relatedAccount` | 关联账户 | `address` |
|
|
157
|
+
| `GET /api/deep/account/transferAmount` | 资金流入/流出分析 | `address` |
|
|
158
|
+
| `GET /api/deep/account/token/bigAmount` | 大额交易 | `address`, `token`, `type` |
|
|
159
|
+
| `GET /api/deep/account/holderToken/basicInfo/trc20/transfer` | 代币转账次数 | `address` |
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## 稳定币分析
|
|
164
|
+
|
|
165
|
+
| 接口 | 用途 | 关键参数 |
|
|
166
|
+
|------|------|----------|
|
|
167
|
+
| `GET /api/stableCoin/holder/balance/overview` | 持仓分布概览 | - |
|
|
168
|
+
| `GET /api/stableCoin/holder/change` | 持有者变化趋势 | - |
|
|
169
|
+
| `GET /api/stableCoin/holder/top` | 大户排行 | - |
|
|
170
|
+
| `GET /api/deep/stableCoin/bigAmount` | 稳定币大额交易 | - |
|
|
171
|
+
| `GET /api/deep/stableCoin/totalSupply/keyEvents` | 增发/销毁/黑名单事件 | - |
|
|
172
|
+
| `GET /api/stableCoin/distribution` | 交易所/DeFi 分布 | - |
|
|
173
|
+
| `GET /api/deep/stableCoin/liquidity/transaction` | 流动性操作记录 | - |
|
|
174
|
+
| `GET /api/stableCoin/pool/overview` | 池子概览(TVL) | - |
|
|
175
|
+
| `GET /api/stableCoin/pool/trend` | 池子趋势 | - |
|
|
176
|
+
| `GET /api/stableCoin/pool/change` | 池子历史变化 | - |
|
|
177
|
+
| `GET /api/stableCoin/tvl` | 稳定币 TVL 分布 | - |
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tronscanteam/cli",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "TronScan API CLI tool - 80+ commands for TRON blockchain data",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/sshnii/tronscan-cli.git"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/sshnii/tronscan-cli/issues"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/sshnii/tronscan-cli#readme",
|
|
14
|
+
"files": [
|
|
15
|
+
"src",
|
|
16
|
+
"README.md",
|
|
17
|
+
"README_CN.md",
|
|
18
|
+
"api-reference.md",
|
|
19
|
+
".env.example"
|
|
20
|
+
],
|
|
21
|
+
"bin": {
|
|
22
|
+
"ts": "src/index.js"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"start": "node src/index.js",
|
|
26
|
+
"dev": "node --watch src/index.js"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"tron",
|
|
30
|
+
"tronscan",
|
|
31
|
+
"blockchain",
|
|
32
|
+
"cli"
|
|
33
|
+
],
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=18"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/api.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import { existsSync, readFileSync } from 'fs';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import { dirname } from 'path';
|
|
5
|
+
|
|
6
|
+
// ============ Config ============
|
|
7
|
+
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = dirname(__filename);
|
|
10
|
+
const PROJECT_ROOT = resolve(__dirname, '..');
|
|
11
|
+
|
|
12
|
+
export const VERSION = '1.0.0';
|
|
13
|
+
const BASE_URL = 'https://apilist.tronscanapi.com';
|
|
14
|
+
|
|
15
|
+
let apiKey = process.env.TRONSCAN_API_KEY || '';
|
|
16
|
+
|
|
17
|
+
export function loadConfig() {
|
|
18
|
+
if (apiKey) return;
|
|
19
|
+
const envPath = resolve(PROJECT_ROOT, '.env');
|
|
20
|
+
if (existsSync(envPath)) {
|
|
21
|
+
const content = readFileSync(envPath, 'utf-8');
|
|
22
|
+
for (const line of content.split('\n')) {
|
|
23
|
+
const match = line.match(/^\s*TRONSCAN_API_KEY\s*=\s*(.+?)\s*$/);
|
|
24
|
+
if (match) {
|
|
25
|
+
apiKey = match[1].replace(/^["']|["']$/g, '');
|
|
26
|
+
process.env.TRONSCAN_API_KEY = apiKey;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (!apiKey) {
|
|
31
|
+
err('未找到 API Key');
|
|
32
|
+
warn('请设置 TRONSCAN_API_KEY 环境变量或创建 .env 文件');
|
|
33
|
+
process.exit(2);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ============ Colors ============
|
|
38
|
+
|
|
39
|
+
const isTTY = process.stderr.isTTY ?? false;
|
|
40
|
+
const c = {
|
|
41
|
+
red: (s) => (isTTY ? `\x1b[31m${s}\x1b[0m` : s),
|
|
42
|
+
green: (s) => (isTTY ? `\x1b[32m${s}\x1b[0m` : s),
|
|
43
|
+
yellow: (s) => (isTTY ? `\x1b[33m${s}\x1b[0m` : s),
|
|
44
|
+
cyan: (s) => (isTTY ? `\x1b[36m${s}\x1b[0m` : s),
|
|
45
|
+
bold: (s) => (isTTY ? `\x1b[1m${s}\x1b[0m` : s),
|
|
46
|
+
dim: (s) => (isTTY ? `\x1b[2m${s}\x1b[0m` : s),
|
|
47
|
+
};
|
|
48
|
+
export { c };
|
|
49
|
+
|
|
50
|
+
export function err(msg) {
|
|
51
|
+
console.error(c.red(`✗ ${msg}`));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function warn(msg) {
|
|
55
|
+
console.error(c.yellow(` ↳ ${msg}`));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// ============ HTTP ============
|
|
59
|
+
|
|
60
|
+
function httpHint(status) {
|
|
61
|
+
if (status === 401 || status === 403) warn('请检查 API Key 是否正确');
|
|
62
|
+
else if (status === 404) warn('接口路径不存在或参数无效');
|
|
63
|
+
else if (status === 429) warn('请求频率超限,请稍后重试');
|
|
64
|
+
else if (status >= 500) warn('服务端异常,请稍后重试');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function get(path) {
|
|
68
|
+
let res;
|
|
69
|
+
try {
|
|
70
|
+
res = await fetch(`${BASE_URL}${path}`, {
|
|
71
|
+
headers: { 'TRON-PRO-API-KEY': apiKey },
|
|
72
|
+
});
|
|
73
|
+
} catch (e) {
|
|
74
|
+
err(`网络请求失败: ${e.message}`);
|
|
75
|
+
warn('请检查网络连接');
|
|
76
|
+
process.exit(3);
|
|
77
|
+
}
|
|
78
|
+
if (!res.ok) {
|
|
79
|
+
err(`请求失败 [HTTP ${res.status}]`);
|
|
80
|
+
httpHint(res.status);
|
|
81
|
+
const body = await res.text();
|
|
82
|
+
if (body) console.error(body);
|
|
83
|
+
process.exit(4);
|
|
84
|
+
}
|
|
85
|
+
return res.json();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export async function post(path, body) {
|
|
89
|
+
let res;
|
|
90
|
+
try {
|
|
91
|
+
res = await fetch(`${BASE_URL}${path}`, {
|
|
92
|
+
method: 'POST',
|
|
93
|
+
headers: {
|
|
94
|
+
'TRON-PRO-API-KEY': apiKey,
|
|
95
|
+
'Content-Type': 'application/json',
|
|
96
|
+
},
|
|
97
|
+
body: typeof body === 'string' ? body : JSON.stringify(body),
|
|
98
|
+
});
|
|
99
|
+
} catch (e) {
|
|
100
|
+
err(`网络请求失败: ${e.message}`);
|
|
101
|
+
warn('请检查网络连接');
|
|
102
|
+
process.exit(3);
|
|
103
|
+
}
|
|
104
|
+
if (!res.ok) {
|
|
105
|
+
err(`请求失败 [HTTP ${res.status}]`);
|
|
106
|
+
httpHint(res.status);
|
|
107
|
+
const text = await res.text();
|
|
108
|
+
if (text) console.error(text);
|
|
109
|
+
process.exit(4);
|
|
110
|
+
}
|
|
111
|
+
return res.json();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// ============ Output ============
|
|
115
|
+
|
|
116
|
+
export function output(data, raw) {
|
|
117
|
+
if (raw) {
|
|
118
|
+
console.log(JSON.stringify(data));
|
|
119
|
+
} else {
|
|
120
|
+
console.log(JSON.stringify(data, null, 2));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// ============ Resolve ============
|
|
125
|
+
|
|
126
|
+
export async function resolveContract(input) {
|
|
127
|
+
if (/^T[A-Za-z0-9]{33}$/.test(input)) return input;
|
|
128
|
+
const data = await get(`/api/search/v2?term=${encodeURIComponent(input)}&start=0&limit=1`);
|
|
129
|
+
const tokens = (data.token || [])
|
|
130
|
+
.filter((t) => t.token_type === 'trc20');
|
|
131
|
+
const lq = input.toLowerCase();
|
|
132
|
+
const match =
|
|
133
|
+
tokens.find((t) => t.abbr?.toLowerCase() === lq) ||
|
|
134
|
+
tokens.find((t) => t.name?.toLowerCase() === lq) ||
|
|
135
|
+
tokens.sort((a, b) => (a.vip ? 0 : 1) - (b.vip ? 0 : 1))[0];
|
|
136
|
+
if (match?.token_id) return match.token_id;
|
|
137
|
+
throw new Error(`无法解析代币: ${input}`);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export async function resolveTrc10(input) {
|
|
141
|
+
if (/^\d+$/.test(input)) return input;
|
|
142
|
+
const data = await get(`/api/search/v2?term=${encodeURIComponent(input)}&start=0&limit=1`);
|
|
143
|
+
const tokens = (data.token || [])
|
|
144
|
+
.filter((t) => t.token_type === 'trc10');
|
|
145
|
+
const lq = input.toLowerCase();
|
|
146
|
+
const match =
|
|
147
|
+
tokens.find((t) => t.abbr?.toLowerCase() === lq) ||
|
|
148
|
+
tokens.find((t) => t.name?.toLowerCase() === lq) ||
|
|
149
|
+
tokens[0];
|
|
150
|
+
if (match?.token_id) return match.token_id;
|
|
151
|
+
throw new Error(`无法解析 TRC10 代币: ${input}`);
|
|
152
|
+
}
|
package/src/commands.js
ADDED
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
import { get, resolveContract, resolveTrc10, err, warn, c } from './api.js';
|
|
2
|
+
|
|
3
|
+
// ============ Helpers ============
|
|
4
|
+
|
|
5
|
+
function require(args, index, name, usage) {
|
|
6
|
+
const val = args[index];
|
|
7
|
+
if (!val) {
|
|
8
|
+
err(`缺少必需参数: ${name}`);
|
|
9
|
+
console.error(` ${c.bold('用法:')} ${usage}`);
|
|
10
|
+
process.exit(2);
|
|
11
|
+
}
|
|
12
|
+
return val;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async function resolveAndLog(input, resolver) {
|
|
16
|
+
const result = await resolver(input);
|
|
17
|
+
if (result !== input) console.error(c.dim(`→ ${input} → ${result}`));
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// ============ Command Definitions ============
|
|
22
|
+
|
|
23
|
+
export const commands = {
|
|
24
|
+
|
|
25
|
+
// --- 账户 ---
|
|
26
|
+
|
|
27
|
+
'account': {
|
|
28
|
+
usage: 'ts account <address>', desc: '账户详情',
|
|
29
|
+
run: (a) => get(`/api/accountv2?address=${require(a, 0, 'address', 'ts account <address>') }`)
|
|
30
|
+
},
|
|
31
|
+
'account-list': {
|
|
32
|
+
usage: 'ts account-list [--start N] [--limit N]', desc: '账户排行榜',
|
|
33
|
+
run: (a, o) => get(`/api/account/list?start=${o.start}&limit=${o.limit}&sort=${o.sort || '-balance'}`)
|
|
34
|
+
},
|
|
35
|
+
'account-tokens': {
|
|
36
|
+
usage: 'ts account-tokens <address>', desc: '持仓代币',
|
|
37
|
+
run: (a, o) => get(`/api/account/tokens?address=${require(a, 0, 'address', 'ts account-tokens <address>')}&start=${o.start}&limit=${o.limit}`)
|
|
38
|
+
},
|
|
39
|
+
'account-resource': {
|
|
40
|
+
usage: 'ts account-resource <address>', desc: 'Stake 2.0 资源(带宽/能量)',
|
|
41
|
+
run: (a) => get(`/api/account/resourcev2?address=${require(a, 0, 'address', 'ts account-resource <address>')}`)
|
|
42
|
+
},
|
|
43
|
+
'account-resource-v1': {
|
|
44
|
+
usage: 'ts account-resource-v1 <address>', desc: 'Stake 1.0 资源',
|
|
45
|
+
run: (a) => get(`/api/account/resource?address=${require(a, 0, 'address', 'ts account-resource-v1 <address>')}`)
|
|
46
|
+
},
|
|
47
|
+
'account-approve': {
|
|
48
|
+
usage: 'ts account-approve <address>', desc: '代币授权列表',
|
|
49
|
+
run: (a, o) => get(`/api/account/approve/list?address=${require(a, 0, 'address', 'ts account-approve <address>')}&start=${o.start}&limit=${o.limit}`)
|
|
50
|
+
},
|
|
51
|
+
'account-approve-change': {
|
|
52
|
+
usage: 'ts account-approve-change <address>', desc: '授权变更历史',
|
|
53
|
+
run: (a, o) => get(`/api/account/approve/change?address=${require(a, 0, 'address', 'ts account-approve-change <address>')}&start=${o.start}&limit=${o.limit}`)
|
|
54
|
+
},
|
|
55
|
+
'account-votes': {
|
|
56
|
+
usage: 'ts account-votes <address>', desc: '投票记录',
|
|
57
|
+
run: (a) => get(`/api/vote?address=${require(a, 0, 'address', 'ts account-votes <address>')}`)
|
|
58
|
+
},
|
|
59
|
+
'account-analysis': {
|
|
60
|
+
usage: 'ts account-analysis <address>', desc: '日度分析',
|
|
61
|
+
run: (a) => get(`/api/account/analysis?address=${require(a, 0, 'address', 'ts account-analysis <address>')}`)
|
|
62
|
+
},
|
|
63
|
+
'account-asset': {
|
|
64
|
+
usage: 'ts account-asset <address>', desc: '持仓总览(含估值)',
|
|
65
|
+
run: (a) => get(`/api/account/token_asset_overview?address=${require(a, 0, 'address', 'ts account-asset <address>')}`)
|
|
66
|
+
},
|
|
67
|
+
'account-projects': {
|
|
68
|
+
usage: 'ts account-projects <address>', desc: '参与项目',
|
|
69
|
+
run: (a) => get(`/api/participate_project?address=${require(a, 0, 'address', 'ts account-projects <address>')}`)
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
// --- 交易 ---
|
|
73
|
+
|
|
74
|
+
'tx': {
|
|
75
|
+
usage: 'ts tx <hash>', desc: '交易详情',
|
|
76
|
+
run: (a) => get(`/api/transaction-info?hash=${require(a, 0, 'hash', 'ts tx <hash>')}`)
|
|
77
|
+
},
|
|
78
|
+
'tx-list': {
|
|
79
|
+
usage: 'ts tx-list [--start N] [--limit N]', desc: '交易列表',
|
|
80
|
+
run: (a, o) => get(`/api/transaction?start=${o.start}&limit=${o.limit}`)
|
|
81
|
+
},
|
|
82
|
+
'tx-stats': {
|
|
83
|
+
usage: 'ts tx-stats', desc: '交易统计',
|
|
84
|
+
run: () => get('/api/transaction/statistics')
|
|
85
|
+
},
|
|
86
|
+
'transfer': {
|
|
87
|
+
usage: 'ts transfer <address>', desc: 'TRX/TRC10 转账',
|
|
88
|
+
run: (a, o) => get(`/api/transfer?address=${require(a, 0, 'address', 'ts transfer <address>')}&start=${o.start}&limit=${o.limit}`)
|
|
89
|
+
},
|
|
90
|
+
'transfer-stats': {
|
|
91
|
+
usage: 'ts transfer-stats', desc: '转账分布统计',
|
|
92
|
+
run: () => get('/api/transfer/statistics')
|
|
93
|
+
},
|
|
94
|
+
'transfer-trc20': {
|
|
95
|
+
usage: 'ts transfer-trc20 <address>', desc: 'TRC20 转账(按地址)',
|
|
96
|
+
run: (a, o) => get(`/api/token_trc20/transfers?relatedAddress=${require(a, 0, 'address', 'ts transfer-trc20 <address>')}&start=${o.start}&limit=${o.limit}`)
|
|
97
|
+
},
|
|
98
|
+
'transfer-trc20-contract': {
|
|
99
|
+
usage: 'ts transfer-trc20-contract <contract>', desc: 'TRC20 转账(按合约)',
|
|
100
|
+
run: (a, o) => get(`/api/token_trc20/transfers?contract_address=${require(a, 0, 'contract', 'ts transfer-trc20-contract <contract>')}&start=${o.start}&limit=${o.limit}`)
|
|
101
|
+
},
|
|
102
|
+
'transfer-trc1155': {
|
|
103
|
+
usage: 'ts transfer-trc1155 <address>', desc: 'TRC1155 转账',
|
|
104
|
+
run: (a, o) => get(`/api/token_trc1155/transfers?relatedAddress=${require(a, 0, 'address', 'ts transfer-trc1155 <address>')}&start=${o.start}&limit=${o.limit}`)
|
|
105
|
+
},
|
|
106
|
+
'transfer-trc721': {
|
|
107
|
+
usage: 'ts transfer-trc721 <contract> <tokenId>', desc: 'TRC721 转账',
|
|
108
|
+
run: (a) => {
|
|
109
|
+
require(a, 0, 'contract', 'ts transfer-trc721 <contract> <tokenId>');
|
|
110
|
+
require(a, 1, 'tokenId', 'ts transfer-trc721 <contract> <tokenId>');
|
|
111
|
+
return get(`/api/trc721/transfers?contract=${a[0]}&tokenId=${a[1]}`);
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
'internal-tx': {
|
|
115
|
+
usage: 'ts internal-tx <address>', desc: '内部交易',
|
|
116
|
+
run: (a, o) => get(`/api/internal-transaction?address=${require(a, 0, 'address', 'ts internal-tx <address>')}&start=${o.start}&limit=${o.limit}`)
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
// --- 区块 ---
|
|
120
|
+
|
|
121
|
+
'block': {
|
|
122
|
+
usage: 'ts block [number]', desc: '最新区块(传区块号查指定区块)',
|
|
123
|
+
run: (a, o) => {
|
|
124
|
+
if (a[0] && /^\d+$/.test(a[0])) {
|
|
125
|
+
return get(`/api/block?number=${a[0]}&limit=1`);
|
|
126
|
+
}
|
|
127
|
+
return get(`/api/block?sort=-number&start=${o.start}&limit=${o.limit || '1'}`);
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
// --- 代币 ---
|
|
132
|
+
|
|
133
|
+
'token': {
|
|
134
|
+
usage: 'ts token <contract|symbol>', desc: 'TRC20 代币详情(支持符号如 USDT)',
|
|
135
|
+
run: async (a) => {
|
|
136
|
+
require(a, 0, 'contract|symbol', 'ts token <contract|symbol>');
|
|
137
|
+
if (a[0].toLowerCase() === 'trx') return get('/api/token?id=0&showAll=1');
|
|
138
|
+
const contract = await resolveAndLog(a[0], resolveContract);
|
|
139
|
+
return get(`/api/token_trc20?contract=${contract}`);
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
'token-trc10': {
|
|
143
|
+
usage: 'ts token-trc10 <id|symbol>', desc: 'TRC10 代币详情',
|
|
144
|
+
run: async (a) => {
|
|
145
|
+
require(a, 0, 'id|symbol', 'ts token-trc10 <id|symbol>');
|
|
146
|
+
const tid = await resolveAndLog(a[0], resolveTrc10);
|
|
147
|
+
return get(`/api/token?id=${tid}`);
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
'token-holders': {
|
|
151
|
+
usage: 'ts token-holders <contract|symbol>', desc: 'TRC20 持有者列表',
|
|
152
|
+
run: async (a, o) => {
|
|
153
|
+
require(a, 0, 'contract|symbol', 'ts token-holders <contract|symbol>');
|
|
154
|
+
const contract = await resolveAndLog(a[0], resolveContract);
|
|
155
|
+
return get(`/api/token_trc20/holders?contract_address=${contract}&start=${o.start}&limit=${o.limit}`);
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
'token-holders-trc10': {
|
|
159
|
+
usage: 'ts token-holders-trc10 <token|symbol>', desc: 'TRC10 持有者列表',
|
|
160
|
+
run: async (a, o) => {
|
|
161
|
+
require(a, 0, 'token|symbol', 'ts token-holders-trc10 <token|symbol>');
|
|
162
|
+
const tid = await resolveAndLog(a[0], resolveTrc10);
|
|
163
|
+
return get(`/api/tokenholders?token=${tid}&start=${o.start}&limit=${o.limit}`);
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
'token-price': {
|
|
167
|
+
usage: 'ts token-price <symbol>', desc: '代币价格',
|
|
168
|
+
run: (a) => {
|
|
169
|
+
require(a, 0, 'symbol', 'ts token-price <symbol>');
|
|
170
|
+
return get(`/api/token/price?token=${a[0].toLowerCase()}`);
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
'token-list': {
|
|
174
|
+
usage: 'ts token-list [--start N] [--limit N]', desc: '代币排行',
|
|
175
|
+
run: (a, o) => get(`/api/tokens/overview?start=${o.start}&limit=${o.limit}`)
|
|
176
|
+
},
|
|
177
|
+
'token-distribution': {
|
|
178
|
+
usage: 'ts token-distribution <token>', desc: '持仓分布',
|
|
179
|
+
run: (a) => get(`/api/tokens/position-distribution?token=${require(a, 0, 'token', 'ts token-distribution <token>')}`)
|
|
180
|
+
},
|
|
181
|
+
|
|
182
|
+
// --- 合约 ---
|
|
183
|
+
|
|
184
|
+
'contract': {
|
|
185
|
+
usage: 'ts contract <address>', desc: '合约详情',
|
|
186
|
+
run: (a) => get(`/api/contract?contract=${require(a, 0, 'address', 'ts contract <address>')}`)
|
|
187
|
+
},
|
|
188
|
+
'contract-list': {
|
|
189
|
+
usage: 'ts contract-list [--start N] [--limit N]', desc: '合约列表',
|
|
190
|
+
run: (a, o) => get(`/api/contracts?start=${o.start}&limit=${o.limit}&sort=${o.sort || '-trxCount'}`)
|
|
191
|
+
},
|
|
192
|
+
'contract-callers': {
|
|
193
|
+
usage: 'ts contract-callers <address>', desc: '调用者排行',
|
|
194
|
+
run: (a) => get(`/api/contracts/top_call?contract_address=${require(a, 0, 'address', 'ts contract-callers <address>')}`)
|
|
195
|
+
},
|
|
196
|
+
'contract-energy': {
|
|
197
|
+
usage: 'ts contract-energy <address>', desc: '能量消耗统计',
|
|
198
|
+
run: (a) => get(`/api/onecontractenergystatistic?address=${require(a, 0, 'address', 'ts contract-energy <address>')}`)
|
|
199
|
+
},
|
|
200
|
+
'contract-daily-callers': {
|
|
201
|
+
usage: 'ts contract-daily-callers <addr> <start_ts> <end_ts>', desc: '每日独立调用者',
|
|
202
|
+
run: (a) => {
|
|
203
|
+
require(a, 0, 'address', 'ts contract-daily-callers <addr> <start_ts> <end_ts>');
|
|
204
|
+
require(a, 1, 'start_timestamp', 'ts contract-daily-callers <addr> <start_ts> <end_ts>');
|
|
205
|
+
require(a, 2, 'end_timestamp', 'ts contract-daily-callers <addr> <start_ts> <end_ts>');
|
|
206
|
+
return get(`/api/onecontractcallerstatistic?address=${a[0]}&start_timestamp=${a[1]}&end_timestamp=${a[2]}`);
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
'contract-daily-calls': {
|
|
210
|
+
usage: 'ts contract-daily-calls <addr> <start_ts> <end_ts>', desc: '每日调用次数',
|
|
211
|
+
run: (a) => {
|
|
212
|
+
require(a, 0, 'address', 'ts contract-daily-calls <addr> <start_ts> <end_ts>');
|
|
213
|
+
require(a, 1, 'start_timestamp', 'ts contract-daily-calls <addr> <start_ts> <end_ts>');
|
|
214
|
+
require(a, 2, 'end_timestamp', 'ts contract-daily-calls <addr> <start_ts> <end_ts>');
|
|
215
|
+
return get(`/api/onecontracttriggerstatistic?address=${a[0]}&start_timestamp=${a[1]}&end_timestamp=${a[2]}`);
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
'contract-analysis': {
|
|
219
|
+
usage: 'ts contract-analysis <address> [type:0-5]', desc: '合约日度分析',
|
|
220
|
+
run: (a) => get(`/api/contract/analysis?address=${require(a, 0, 'address', 'ts contract-analysis <address> [type:0-5]')}&type=${a[1] || '0'}`)
|
|
221
|
+
},
|
|
222
|
+
'contract-all-callers': {
|
|
223
|
+
usage: 'ts contract-all-callers <address> [day]', desc: '所有调用者列表',
|
|
224
|
+
run: (a, o) => get(`/api/onecontractcallers?address=${require(a, 0, 'address', 'ts contract-all-callers <address> [day]')}&day=${a[1] || '1'}&start=${o.start}&limit=${o.limit}`)
|
|
225
|
+
},
|
|
226
|
+
'contract-triggers': {
|
|
227
|
+
usage: 'ts contract-triggers [--start N] [--limit N]', desc: '合约触发交易',
|
|
228
|
+
run: (a, o) => get(`/api/contracts/trigger?start=${o.start}&limit=${o.limit}`)
|
|
229
|
+
},
|
|
230
|
+
|
|
231
|
+
// --- 超级代表 ---
|
|
232
|
+
|
|
233
|
+
'sr': {
|
|
234
|
+
usage: 'ts sr [type: 0=SR, 1=partner, 3=candidate]', desc: 'SR 列表',
|
|
235
|
+
run: (a) => get(`/api/pagewitness?witnesstype=${a[0] || '0'}`)
|
|
236
|
+
},
|
|
237
|
+
'sr-votes': {
|
|
238
|
+
usage: 'ts sr-votes <address>', desc: 'SR 投票详情',
|
|
239
|
+
run: (a) => get(`/api/vote/witness?address=${require(a, 0, 'address', 'ts sr-votes <address>')}`)
|
|
240
|
+
},
|
|
241
|
+
'params': {
|
|
242
|
+
usage: 'ts params', desc: '链参数',
|
|
243
|
+
run: () => get('/api/chainparameters')
|
|
244
|
+
},
|
|
245
|
+
'proposal': {
|
|
246
|
+
usage: 'ts proposal <id>', desc: '提案详情',
|
|
247
|
+
run: (a) => get(`/api/proposal?id=${require(a, 0, 'id', 'ts proposal <id>')}`)
|
|
248
|
+
},
|
|
249
|
+
|
|
250
|
+
// --- 安全 ---
|
|
251
|
+
|
|
252
|
+
'security-account': {
|
|
253
|
+
usage: 'ts security-account <address>', desc: '账户风险检测',
|
|
254
|
+
run: (a) => get(`/api/security/account/data?address=${require(a, 0, 'address', 'ts security-account <address>')}`)
|
|
255
|
+
},
|
|
256
|
+
'security-token': {
|
|
257
|
+
usage: 'ts security-token <address>', desc: '代币安全检测',
|
|
258
|
+
run: (a) => get(`/api/security/token/data?address=${require(a, 0, 'address', 'ts security-token <address>')}`)
|
|
259
|
+
},
|
|
260
|
+
'security-url': {
|
|
261
|
+
usage: 'ts security-url <url>', desc: 'URL 钓鱼检测',
|
|
262
|
+
run: (a) => get(`/api/security/url/data?url=${require(a, 0, 'url', 'ts security-url <url>')}`)
|
|
263
|
+
},
|
|
264
|
+
'security-tx': {
|
|
265
|
+
usage: 'ts security-tx <hash>', desc: '交易风险检测',
|
|
266
|
+
run: (a) => get(`/api/security/transaction/data?hashes=${require(a, 0, 'hash', 'ts security-tx <hash>')}`)
|
|
267
|
+
},
|
|
268
|
+
'security-auth': {
|
|
269
|
+
usage: 'ts security-auth <address>', desc: '授权风险检查',
|
|
270
|
+
run: (a) => get(`/api/security/auth/data?address=${require(a, 0, 'address', 'ts security-auth <address>')}`)
|
|
271
|
+
},
|
|
272
|
+
'security-sign': {
|
|
273
|
+
usage: 'ts security-sign <address>', desc: '多签配置检查',
|
|
274
|
+
run: (a) => get(`/api/security/sign/data?address=${require(a, 0, 'address', 'ts security-sign <address>')}`)
|
|
275
|
+
},
|
|
276
|
+
|
|
277
|
+
// --- 搜索 ---
|
|
278
|
+
|
|
279
|
+
'search': {
|
|
280
|
+
usage: 'ts search <keyword>', desc: '搜索',
|
|
281
|
+
run: (a, o) => get(`/api/search/v2?term=${require(a, 0, 'keyword', 'ts search <keyword>')}&start=0&limit=${o.limit || '10'}`)
|
|
282
|
+
},
|
|
283
|
+
'tps': {
|
|
284
|
+
usage: 'ts tps', desc: '当前 TPS',
|
|
285
|
+
run: () => get('/api/system/tps')
|
|
286
|
+
},
|
|
287
|
+
'overview': {
|
|
288
|
+
usage: 'ts overview', desc: 'TRON 网络概览',
|
|
289
|
+
run: () => get('/api/system/homepage-bundle')
|
|
290
|
+
},
|
|
291
|
+
'hot-token': {
|
|
292
|
+
usage: 'ts hot-token', desc: '热搜代币排行',
|
|
293
|
+
run: () => get('/api/search/hot')
|
|
294
|
+
},
|
|
295
|
+
'nodes': {
|
|
296
|
+
usage: 'ts nodes', desc: '全网节点信息',
|
|
297
|
+
run: () => get('/api/nodemap')
|
|
298
|
+
},
|
|
299
|
+
|
|
300
|
+
// --- 统计 ---
|
|
301
|
+
|
|
302
|
+
'trx-supply': {
|
|
303
|
+
usage: 'ts trx-supply', desc: 'TRX 供应/销毁',
|
|
304
|
+
run: () => get('/api/funds')
|
|
305
|
+
},
|
|
306
|
+
'trx-turnover': {
|
|
307
|
+
usage: 'ts trx-turnover', desc: 'TRX 发行与销毁分析',
|
|
308
|
+
run: () => get('/api/turnover')
|
|
309
|
+
},
|
|
310
|
+
'tx-trend': {
|
|
311
|
+
usage: 'ts tx-trend', desc: '每日交易趋势',
|
|
312
|
+
run: () => get('/api/overview/dailytransactionnum')
|
|
313
|
+
},
|
|
314
|
+
'tx-total': {
|
|
315
|
+
usage: 'ts tx-total', desc: '累计交易数',
|
|
316
|
+
run: () => get('/api/overview/transactionnum')
|
|
317
|
+
},
|
|
318
|
+
'active-accounts': {
|
|
319
|
+
usage: 'ts active-accounts', desc: '活跃账户',
|
|
320
|
+
run: () => get('/api/account/active_statistic')
|
|
321
|
+
},
|
|
322
|
+
'new-accounts': {
|
|
323
|
+
usage: 'ts new-accounts', desc: '新增账户',
|
|
324
|
+
run: () => get('/api/overview/dailyaccounts')
|
|
325
|
+
},
|
|
326
|
+
'defi-tvl': {
|
|
327
|
+
usage: 'ts defi-tvl', desc: 'DeFi TVL',
|
|
328
|
+
run: () => get('/api/defiTvl')
|
|
329
|
+
},
|
|
330
|
+
'top10': {
|
|
331
|
+
usage: 'ts top10', desc: 'Top 10 排行',
|
|
332
|
+
run: () => get('/api/top10')
|
|
333
|
+
},
|
|
334
|
+
'trx-price': {
|
|
335
|
+
usage: 'ts trx-price', desc: 'TRX 价格历史',
|
|
336
|
+
run: () => get('/api/trx/volume')
|
|
337
|
+
},
|
|
338
|
+
'energy-daily': {
|
|
339
|
+
usage: 'ts energy-daily', desc: '每日能量消耗',
|
|
340
|
+
run: () => get('/api/energydailystatistic')
|
|
341
|
+
},
|
|
342
|
+
'energy-dist': {
|
|
343
|
+
usage: 'ts energy-dist', desc: '能量消耗分布',
|
|
344
|
+
run: () => get('/api/energystatistic')
|
|
345
|
+
},
|
|
346
|
+
'energy-cost': {
|
|
347
|
+
usage: 'ts energy-cost', desc: '能量/带宽获取成本',
|
|
348
|
+
run: () => get('/api/acquisition_cost_statistic')
|
|
349
|
+
},
|
|
350
|
+
'bandwidth-daily': {
|
|
351
|
+
usage: 'ts bandwidth-daily', desc: '每日带宽消耗',
|
|
352
|
+
run: () => get('/api/netstatistic')
|
|
353
|
+
},
|
|
354
|
+
'trigger-stats': {
|
|
355
|
+
usage: 'ts trigger-stats', desc: '合约调用分布',
|
|
356
|
+
run: () => get('/api/triggeramountstatistic')
|
|
357
|
+
},
|
|
358
|
+
'token-tvc': {
|
|
359
|
+
usage: 'ts token-tvc', desc: '代币链上价值(TVC)',
|
|
360
|
+
run: () => get('/api/tokenTvc')
|
|
361
|
+
},
|
|
362
|
+
'token-analysis': {
|
|
363
|
+
usage: 'ts token-analysis', desc: '代币交易分析',
|
|
364
|
+
run: () => get('/api/token/analysis')
|
|
365
|
+
},
|
|
366
|
+
'token-transfer-analysis': {
|
|
367
|
+
usage: 'ts token-transfer-analysis', desc: '代币转账分析',
|
|
368
|
+
run: () => get('/api/tokenTransfer/analysis')
|
|
369
|
+
},
|
|
370
|
+
|
|
371
|
+
// --- 深度分析 ---
|
|
372
|
+
|
|
373
|
+
'deep-related': {
|
|
374
|
+
usage: 'ts deep-related <address>', desc: '关联账户',
|
|
375
|
+
run: (a) => get(`/api/deep/account/relatedAccount?address=${require(a, 0, 'address', 'ts deep-related <address>')}`)
|
|
376
|
+
},
|
|
377
|
+
'deep-flow': {
|
|
378
|
+
usage: 'ts deep-flow <address>', desc: '资金流向',
|
|
379
|
+
run: (a) => get(`/api/deep/account/transferAmount?address=${require(a, 0, 'address', 'ts deep-flow <address>')}`)
|
|
380
|
+
},
|
|
381
|
+
'deep-big-tx': {
|
|
382
|
+
usage: 'ts deep-big-tx <address>', desc: '大额交易',
|
|
383
|
+
run: (a) => get(`/api/deep/account/token/bigAmount?address=${require(a, 0, 'address', 'ts deep-big-tx <address>')}`)
|
|
384
|
+
},
|
|
385
|
+
'deep-token-transfer': {
|
|
386
|
+
usage: 'ts deep-token-transfer <address>', desc: '代币转账次数',
|
|
387
|
+
run: (a) => get(`/api/deep/account/holderToken/basicInfo/trc20/transfer?address=${require(a, 0, 'address', 'ts deep-token-transfer <address>')}`)
|
|
388
|
+
},
|
|
389
|
+
|
|
390
|
+
// --- 稳定币 ---
|
|
391
|
+
|
|
392
|
+
'stable-holders': {
|
|
393
|
+
usage: 'ts stable-holders', desc: '持仓分布概览',
|
|
394
|
+
run: () => get('/api/stableCoin/holder/balance/overview')
|
|
395
|
+
},
|
|
396
|
+
'stable-change': {
|
|
397
|
+
usage: 'ts stable-change', desc: '持有者变化趋势',
|
|
398
|
+
run: () => get('/api/stableCoin/holder/change')
|
|
399
|
+
},
|
|
400
|
+
'stable-top': {
|
|
401
|
+
usage: 'ts stable-top', desc: '大户排行',
|
|
402
|
+
run: () => get('/api/stableCoin/holder/top')
|
|
403
|
+
},
|
|
404
|
+
'stable-big-tx': {
|
|
405
|
+
usage: 'ts stable-big-tx', desc: '大额交易',
|
|
406
|
+
run: () => get('/api/deep/stableCoin/bigAmount')
|
|
407
|
+
},
|
|
408
|
+
'stable-events': {
|
|
409
|
+
usage: 'ts stable-events', desc: '增发/销毁/黑名单事件',
|
|
410
|
+
run: () => get('/api/deep/stableCoin/totalSupply/keyEvents')
|
|
411
|
+
},
|
|
412
|
+
'stable-dist': {
|
|
413
|
+
usage: 'ts stable-dist', desc: '交易所/DeFi 分布',
|
|
414
|
+
run: () => get('/api/stableCoin/distribution')
|
|
415
|
+
},
|
|
416
|
+
'stable-liquidity': {
|
|
417
|
+
usage: 'ts stable-liquidity', desc: '流动性操作记录',
|
|
418
|
+
run: () => get('/api/deep/stableCoin/liquidity/transaction')
|
|
419
|
+
},
|
|
420
|
+
'stable-pool': {
|
|
421
|
+
usage: 'ts stable-pool', desc: '池子概览(TVL)',
|
|
422
|
+
run: () => get('/api/stableCoin/pool/overview')
|
|
423
|
+
},
|
|
424
|
+
'stable-pool-trend': {
|
|
425
|
+
usage: 'ts stable-pool-trend', desc: '池子趋势',
|
|
426
|
+
run: () => get('/api/stableCoin/pool/trend')
|
|
427
|
+
},
|
|
428
|
+
'stable-pool-change': {
|
|
429
|
+
usage: 'ts stable-pool-change', desc: '池子历史变化',
|
|
430
|
+
run: () => get('/api/stableCoin/pool/change')
|
|
431
|
+
},
|
|
432
|
+
'stable-tvl': {
|
|
433
|
+
usage: 'ts stable-tvl', desc: '稳定币 TVL 分布',
|
|
434
|
+
run: () => get('/api/stableCoin/tvl')
|
|
435
|
+
},
|
|
436
|
+
|
|
437
|
+
// --- 兜底 ---
|
|
438
|
+
|
|
439
|
+
'api': {
|
|
440
|
+
usage: 'ts api "/api/xxx?param=value"', desc: '直接调用 API',
|
|
441
|
+
run: (a) => get(require(a, 0, 'path', 'ts api "/api/xxx?param=value"'))
|
|
442
|
+
},
|
|
443
|
+
};
|
package/src/help.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { VERSION, c } from './api.js';
|
|
2
|
+
|
|
3
|
+
export function printHelp() {
|
|
4
|
+
const isTTY = process.stdout.isTTY ?? false;
|
|
5
|
+
const B = (s) => (isTTY ? `\x1b[1m${s}\x1b[0m` : s);
|
|
6
|
+
const C = (s) => (isTTY ? `\x1b[36m${s}\x1b[0m` : s);
|
|
7
|
+
|
|
8
|
+
console.log(`${B(`TronScan CLI v${VERSION}`)} - TRON 链上数据查询工具
|
|
9
|
+
|
|
10
|
+
${C('用法:')} ts <command> [args...] [options...]
|
|
11
|
+
|
|
12
|
+
${B('全局选项:')}
|
|
13
|
+
--start N 分页起始位置(默认 0)
|
|
14
|
+
--limit N 每页数量(默认 20)
|
|
15
|
+
--sort FIELD 排序字段
|
|
16
|
+
--raw 输出紧凑 JSON(适合管道)
|
|
17
|
+
--help, -h 显示命令帮助
|
|
18
|
+
--version, -V 显示版本号
|
|
19
|
+
|
|
20
|
+
代币:
|
|
21
|
+
ts token <contract|symbol> TRC20 代币详情(支持 USDT 等符号)
|
|
22
|
+
ts token-trc10 <id|symbol> TRC10 代币详情
|
|
23
|
+
ts token-holders <contract|symbol> TRC20 持有者列表
|
|
24
|
+
ts token-holders-trc10 <token|symbol> TRC10 持有者列表
|
|
25
|
+
ts token-price <symbol> 代币价格(如 trx、usdt)
|
|
26
|
+
ts token-list 代币排行
|
|
27
|
+
ts token-distribution <token> 持仓分布
|
|
28
|
+
|
|
29
|
+
搜索:
|
|
30
|
+
ts search <keyword> 搜索
|
|
31
|
+
ts hot-token 热搜代币排行
|
|
32
|
+
|
|
33
|
+
概览:
|
|
34
|
+
ts tps 当前 TPS
|
|
35
|
+
ts overview TRON 网络概览
|
|
36
|
+
ts nodes 全网节点信息
|
|
37
|
+
|
|
38
|
+
区块:
|
|
39
|
+
ts block [number] 最新区块(传区块号查指定区块)
|
|
40
|
+
|
|
41
|
+
账户:
|
|
42
|
+
ts account <addr> 账户详情
|
|
43
|
+
ts account-list 账户排行榜
|
|
44
|
+
ts account-tokens <addr> 持仓代币
|
|
45
|
+
ts account-resource <addr> Stake 2.0 资源(带宽/能量)
|
|
46
|
+
ts account-resource-v1 <addr> Stake 1.0 资源
|
|
47
|
+
ts account-approve <addr> 代币授权列表
|
|
48
|
+
ts account-approve-change <addr> 授权变更历史
|
|
49
|
+
ts account-votes <addr> 投票记录
|
|
50
|
+
ts account-analysis <addr> 日度分析
|
|
51
|
+
ts account-asset <addr> 持仓总览(含估值)
|
|
52
|
+
ts account-projects <addr> 参与项目
|
|
53
|
+
|
|
54
|
+
超级代表:
|
|
55
|
+
ts sr [type] SR 列表 (0=SR,1=partner,3=candidate)
|
|
56
|
+
ts sr-votes <addr> SR 投票详情
|
|
57
|
+
ts params 链参数
|
|
58
|
+
ts proposal <id> 提案详情
|
|
59
|
+
|
|
60
|
+
交易:
|
|
61
|
+
ts tx <hash> 交易详情
|
|
62
|
+
ts tx-list 交易列表
|
|
63
|
+
ts tx-stats 交易统计
|
|
64
|
+
ts transfer <addr> TRX/TRC10 转账
|
|
65
|
+
ts transfer-stats 转账分布统计
|
|
66
|
+
ts transfer-trc20 <addr> TRC20 转账(按地址)
|
|
67
|
+
ts transfer-trc20-contract <contract> TRC20 转账(按合约)
|
|
68
|
+
ts transfer-trc1155 <addr> TRC1155 转账
|
|
69
|
+
ts transfer-trc721 <contract> <tokenId> TRC721 转账
|
|
70
|
+
ts internal-tx <addr> 内部交易
|
|
71
|
+
|
|
72
|
+
统计:
|
|
73
|
+
ts trx-supply TRX 供应/销毁
|
|
74
|
+
ts trx-turnover TRX 发行与销毁分析
|
|
75
|
+
ts tx-trend 每日交易趋势
|
|
76
|
+
ts tx-total 累计交易数
|
|
77
|
+
ts active-accounts 活跃账户
|
|
78
|
+
ts new-accounts 新增账户
|
|
79
|
+
ts defi-tvl DeFi TVL
|
|
80
|
+
ts top10 Top 10 排行
|
|
81
|
+
ts trx-price TRX 价格历史
|
|
82
|
+
ts energy-daily 每日能量消耗
|
|
83
|
+
ts energy-dist 能量消耗分布
|
|
84
|
+
ts energy-cost 能量/带宽获取成本
|
|
85
|
+
ts bandwidth-daily 每日带宽消耗
|
|
86
|
+
ts trigger-stats 合约调用分布
|
|
87
|
+
ts token-tvc 代币链上价值(TVC)
|
|
88
|
+
ts token-analysis 代币交易分析
|
|
89
|
+
ts token-transfer-analysis 代币转账分析
|
|
90
|
+
|
|
91
|
+
合约:
|
|
92
|
+
ts contract <addr> 合约详情
|
|
93
|
+
ts contract-list 合约列表
|
|
94
|
+
ts contract-callers <addr> 调用者排行
|
|
95
|
+
ts contract-energy <addr> 能量消耗统计
|
|
96
|
+
ts contract-daily-callers <addr> <start_ts> <end_ts> 每日独立调用者
|
|
97
|
+
ts contract-daily-calls <addr> <start_ts> <end_ts> 每日调用次数
|
|
98
|
+
ts contract-analysis <addr> [type] 合约日度分析(type:0-5)
|
|
99
|
+
ts contract-all-callers <addr> [day] 所有调用者列表
|
|
100
|
+
ts contract-triggers 合约触发交易
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
安全:
|
|
104
|
+
ts security-account <addr> 账户风险检测
|
|
105
|
+
ts security-token <addr> 代币安全检测
|
|
106
|
+
ts security-url <url> URL 钓鱼检测
|
|
107
|
+
ts security-tx <hash> 交易风险检测
|
|
108
|
+
ts security-auth <addr> 授权风险检查
|
|
109
|
+
ts security-sign <addr> 多签配置检查
|
|
110
|
+
|
|
111
|
+
深度分析:
|
|
112
|
+
ts deep-related <addr> 关联账户
|
|
113
|
+
ts deep-flow <addr> 资金流向
|
|
114
|
+
ts deep-big-tx <addr> 大额交易
|
|
115
|
+
ts deep-token-transfer <addr> 代币转账次数
|
|
116
|
+
|
|
117
|
+
稳定币:
|
|
118
|
+
ts stable-holders 持仓分布概览
|
|
119
|
+
ts stable-change 持有者变化趋势
|
|
120
|
+
ts stable-top 大户排行
|
|
121
|
+
ts stable-big-tx 大额交易
|
|
122
|
+
ts stable-events 增发/销毁/黑名单事件
|
|
123
|
+
ts stable-dist 交易所/DeFi 分布
|
|
124
|
+
ts stable-liquidity 流动性操作记录
|
|
125
|
+
ts stable-pool 池子概览(TVL)
|
|
126
|
+
ts stable-pool-trend 池子趋势
|
|
127
|
+
ts stable-pool-change 池子历史变化
|
|
128
|
+
ts stable-tvl 稳定币 TVL 分布
|
|
129
|
+
`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function printCommandHelp(name, usage, desc) {
|
|
133
|
+
const isTTY = process.stdout.isTTY ?? false;
|
|
134
|
+
const B = (s) => (isTTY ? `\x1b[1m${s}\x1b[0m` : s);
|
|
135
|
+
const C = (s) => (isTTY ? `\x1b[36m${s}\x1b[0m` : s);
|
|
136
|
+
|
|
137
|
+
console.log(`${B('用法:')} ${usage}`);
|
|
138
|
+
console.log(` ${C(desc)}\n`);
|
|
139
|
+
console.log(` 全局选项: --raw (紧凑JSON) --start N --limit N --sort FIELD`);
|
|
140
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { loadConfig, output, err, warn, VERSION } from './api.js';
|
|
4
|
+
import { commands } from './commands.js';
|
|
5
|
+
import { printHelp, printCommandHelp } from './help.js';
|
|
6
|
+
|
|
7
|
+
// ============ Parse arguments ============
|
|
8
|
+
|
|
9
|
+
const rawArgs = process.argv.slice(2);
|
|
10
|
+
|
|
11
|
+
// --version / -V
|
|
12
|
+
if (rawArgs[0] === '--version' || rawArgs[0] === '-V' || rawArgs[0] === 'version') {
|
|
13
|
+
console.log(`TronScan CLI v${VERSION}`);
|
|
14
|
+
process.exit(0);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// --help / -h (no command)
|
|
18
|
+
if (!rawArgs[0] || rawArgs[0] === '--help' || rawArgs[0] === '-h' || rawArgs[0] === 'help') {
|
|
19
|
+
printHelp();
|
|
20
|
+
process.exit(0);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Extract command
|
|
24
|
+
const cmd = rawArgs[0];
|
|
25
|
+
const rest = rawArgs.slice(1);
|
|
26
|
+
|
|
27
|
+
// Parse options and positional args
|
|
28
|
+
const opts = { start: '0', limit: '20', sort: '', raw: false };
|
|
29
|
+
let showHelp = false;
|
|
30
|
+
const positional = [];
|
|
31
|
+
|
|
32
|
+
let i = 0;
|
|
33
|
+
while (i < rest.length) {
|
|
34
|
+
const arg = rest[i];
|
|
35
|
+
switch (arg) {
|
|
36
|
+
case '--raw': opts.raw = true; i++; break;
|
|
37
|
+
case '--help':
|
|
38
|
+
case '-h': showHelp = true; i++; break;
|
|
39
|
+
case '--start': opts.start = rest[++i] || '0'; i++; break;
|
|
40
|
+
case '--limit': opts.limit = rest[++i] || '20'; i++; break;
|
|
41
|
+
case '--sort': opts.sort = rest[++i] || ''; i++; break;
|
|
42
|
+
case '--': positional.push(...rest.slice(++i)); i = rest.length; break;
|
|
43
|
+
default: positional.push(arg); i++; break;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ============ Dispatch ============
|
|
48
|
+
|
|
49
|
+
const command = commands[cmd];
|
|
50
|
+
|
|
51
|
+
if (!command) {
|
|
52
|
+
err(`未知命令: ${cmd}`);
|
|
53
|
+
warn('输入 ts help 查看帮助');
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (showHelp) {
|
|
58
|
+
printCommandHelp(cmd, command.usage, command.desc);
|
|
59
|
+
process.exit(0);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Load config and run
|
|
63
|
+
loadConfig();
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
const result = await command.run(positional, opts);
|
|
67
|
+
output(result, opts.raw);
|
|
68
|
+
} catch (e) {
|
|
69
|
+
err(e.message);
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|