与 TRON (波场) 区块链进行交互的命令行工具 (CLI): tstroncli

发布于:2025-07-27 ⋅ 阅读:(15) ⋅ 点赞:(0)

源码仓库

在这里插入图片描述

一个基于 Node.js 和 TypeScript 构建的,用于与 TRON (波场) 区块链进行交互的命令行工具 (CLI)。

本项目旨在提供一个简单、可扩展的框架,让开发者可以轻松地通过命令行调用 TRON 的 HTTP API,实现查询链上信息、发送交易等操作。

✨ 功能特性

  • 交互式命令行: 在终端中提供一个持续运行的交互式提示符。
  • 清晰的架构: 命令逻辑、定义和主程序分离,易于理解和维护。
  • 易于扩展: 添加新命令只需修改一个文件,无需改动核心逻辑。
  • TypeScript 支持: 完整的类型定义,提供更好的开发体验和代码健壮性。
  • 美观的输出: 使用 chalkfiglet 美化输出,使用 console.table 格式化帮助信息。

🚀 安装

源码仓库

📖 使用说明

tstroncli程序启动后,你可以输入相应的命令并按回车键来执行。

可用命令

输入 /help 可以查看所有支持的命令及其说明:
在这里插入图片描述

(index) 方法名 中文解释 英文解释
0 createrandom 创建 12 位的助记词 Create a 12-word mnemonic phrase
1 createaccount 创建地址账号 <未激活的新地址> Create an address account
2 getaccount 根据地址查询账户信息。用法: getaccount <address: b58 hex>
3 getaccountresources 获取账号中的能量和带宽资源。用法: getaccount <address: b58 hex>
4 getgenesisblock 获取创世区块(最早的区块)信息 Get information about the genesis block (earliest block)
5 getnowblock 获取最新的区块信息 Get information about the latest block
6 getblocknumber 获取最新的区块信息 Get the latest block number
7 getbalance 获取账户可用 TRX 余额。用法: getbalance <address: b58 hex>
8 getbandwidth 获取账户可用带宽余额。用法: getbandwidth <address: b58 hex>
9 getbandwidthprices 查询历史带宽单价 Query historical bandwidth unit prices
10 getblock 通过区块高度或区块 ID 查询区块信息。用法: getblock <blockNumber blockId
11 getblockbyhash 通过区块 ID 查询区块信息。用法: getblock Query block information by block ID. Usage: getblock
12 getblockbynumber 通过区块高度查询区块信息。用法: getblockbynumber Query block information by block height. Usage: getblockbynumber
13 getblockrange 通过区块高度区间查询区块信息。用法: getblockrange <startBlockNumber, endBlockNumber> Query block information by block height range. Usage: getblockrange <startBlockNumber, endBlockNumber>
14 getblocktransactioncount 检索区块内的交易数量。用法: getBlockTransactionCount <blockHeight blockHash
15 getbrokerage 获取 SR 经纪佣金比例。用法: getbrokerage
Get the SR brokerage commission ratio. Usage: getbrokerage
16 getnodeinfo 查询节点信息 Query node information
17 gettokenlistbyname 通过代币名称 查询 TRC10 代币列表信息。用法: gettokenlistbyname Query TRC10 token list information by token name. Usage: gettokenlistbyname
18 gettokenbyid 通过代币 id 查询 TRC10 代币信息。用法: gettokenbyid Query TRC10 token information by token ID. Usage: gettokenbyid
19 gettokenfromid 通过代币 id 查询 TRC10 代币信息。用法: gettokenfromid Query TRC10 token information by token ID. Usage: gettokenfromid
20 gettokensissuedbyaddress 查询账户的 TRC10 代币发行信息。用法: gettokensissuedbyaddress <address: b58 hex>
21 gettransaction 通过交易 id 查询交易信息。用法: gettransaction Query transaction information by transaction ID. Usage: gettransaction
22 sendtoken 交易 TRC10。用法: sendtoken <to: b58, amount: 1 (对应代币最小单位), tokenID: 代币 ID> Transfer TRC10 tokens. Usage: sendtoken <to: b58, amount: 1 (smallest token unit), tokenID: token ID>
23 sendrawtransaction 交易 TRX。用法: sendrawtransaction <to: b58, amount: 1 (单位: TRX)> Transfer TRX. Usage: sendrawtransaction <to: b58, amount: 1 (unit: TRX)>
24 sendtrc20 交易 TRC20(注意:此交易会消耗 100TRX)。用法: sendtrc20 <to: b58, amount: 代币数量, contractAddress: 合约地址> Transfer TRC20 tokens (Note: consumes 100 TRX). Usage: sendtrc20 <to: b58, amount: token amount, contractAddress: contract address>
25 sign 交易签名(并未广播上链)。用法: sign <from: b58, amount: 1 (单位 TRX), to: b58> Sign a transaction (not broadcasted). Usage: sign <from: b58, amount: 1 (unit TRX), to: b58>
26 sendhextransaction 交易签名(将上一步的 sign 广播上链)。用法: sendhextransaction Broadcast a signed transaction. Usage: sendhextransaction
27 delegatebandwidth 代理带宽。用法: delegatebandwidth <to: b58, amount> Delegate bandwidth. Usage: delegatebandwidth <to: b58, amount>
28 undelegatebandwidth 回收带宽。用法: undelegatebandwidth <from: b58, amount> Undelegate bandwidth. Usage: undelegatebandwidth <from: b58, amount>
29 delegateenergy 代理能量。用法: delegateenergy <to: b58, amount> Delegate energy. Usage: delegateenergy <to: b58, amount>
30 undelegateenergy 回收带宽。用法: undelegateenergy <from: b58, amount> Undelegate energy. Usage: undelegateenergy <from: b58, amount>
31 frommnemonic 根据助记词回复地址和私钥 用法: frommnemonic
32 suntotrx sun to trx。用法: suntotrx Convert sun to TRX. Usage: suntotrx
33 isaddress isAddress。用法: isaddress <address: b58 hex>
34 tobignumber to big number。用法: tobignumber Convert to big number. Usage: tobignumber
35 todecimal to decimal: todecimal <value: 0x15> Convert to decimal. Usage: todecimal <value: 0x15>

项目还在开发中,命令尚未加完.如果你愿意,很乐意你参与其中加入新的命令

源码仓库


网站公告

今日签到

点亮在社区的每一天
去签到