关于 query
Query Skill 通过 Hiro API 提供 Stacks 网络和区块链查询,适用于需要查看账户、区块、合约或网络状态的用户。它还支持读取待处理交易、合约事件及调用只读合约函数。
主要功能
- 01查询 STX 手续费估算
- 02查看账户余额与交易记录
- 03查询区块和网络状态
- 04读取合约信息与事件
- 05调用只读合约函数
适用场景
- 01查看账户余额和 nonce
- 02检查待处理交易及网络状态
- 03读取合约 ABI 或事件
- 04查询只读合约函数的结果
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ aibtcdev/ skills --skill query安装后在 Claude Code 中输入/query确认已加载。
附带文件AGENT.mdquery.ts
详细介绍
查询技能
使用 Hiro API 提供 Stacks 网络和区块链查询操作。大多数查询无需钱包;如果未提供地址,get-account-info 和 get-account-transactions 会回退到当前钱包地址。
用法
bun run query/query.ts <subcommand> [options]
子命令
get-stx-fees
获取不同优先级的当前 STX 费用估算。
bun run query/query.ts get-stx-fees
输出:
{
"network": "mainnet",
"fees": {
"low": { "microStx": 1000, "stx": "0.001 STX", "description": "Lower fee, may take longer to confirm" },
"medium": { "microStx": 2500, "stx": "0.0025 STX", "description": "Standard fee, typical confirmation time" },
"high": { "microStx": 5000, "stx": "0.005 STX", "description": "Higher fee, faster confirmation" }
},
"byTransactionType": {
"tokenTransfer": { "low": 1000, "medium": 2500, "high": 5000 },
"contractCall": { "low": 1500, "medium": 3000, "high": 6000 },
"smartContract": { "low": 2000, "medium": 4000, "high": 8000 }
},
"unit": "micro-STX",
"note": "1 STX = 1,000,000 micro-STX. Fees are estimates based on current mempool conditions."
}
get-account-info
获取账户信息,包括 nonce 和 STX 余额。
bun run query/query.ts get-account-info [--address <stxAddress>]
选项:
--address(可选)— 要查询的 Stacks 地址(如果省略,则使用当前钱包)
输出:
{
"address": "SP...",
"network": "mainnet",
"nonce": 42,
"balance": { "microStx": "1000000000", "stx": "1000 STX" },
"explorerUrl": "https://explorer.hiro.so/address/SP...?chain=mainnet"
}
get-account-transactions
获取 Stacks 账户的交易历史记录。
bun run query/query.ts get-account-transactions [--address <stxAddress>] [--limit 20] [--offset 0]
选项:
--address(可选)— Stacks 地址(如果省略,则使用当前钱包)--limit(可选)— 最大结果数(默认值:20)--offset(可选)— 分页偏移量(默认值:0)
输出:
{
"address": "SP...",
"network": "mainnet",
"total": 150,
"limit": 20,
"offset": 0,
"transactions": [
{
"txId": "0x...",
"type": "token_transfer",
"status": "success",
"sender": "SP...",
"blockHeight": 145000,
"fee": "1000",
"explorerUrl": "https://explorer.hiro.so/txid/0x...?chain=mainnet"
}
],
"explorerUrl": "https://explorer.hiro.so/address/SP...?chain=mainnet"
}
get-block-info
获取特定 Stacks 区块的信息。
bun run query/query.ts get-block-info --height-or-hash <value>
选项:
--height-or-hash(必需)— 区块高度(整数)或区块哈希(以 0x 为前缀)
输出:
{
"network": "mainnet",
"hash": "0x...",
"height": 145000,
"canonical": true,
"burnBlockHeight": 840000,
"burnBlockTime": 1700000000,
"burnBlockTimeIso": "2024-01-01T00:00:00.000Z",
"txCount": 12,
"txIds": ["0x..."]
}
get-mempool-info
获取 Stacks 内存池中的待处理交易。
bun run query/query.ts get-mempool-info [--sender-address <addr>] [--limit 20] [--offset 0]
选项:
--sender-address(可选)— 按发送方地址筛选--limit(可选)— 最大结果数(默认值:20)--offset(可选)— 分页偏移量(默认值:0)
输出:
{
"network": "mainnet",
"total": 5,
"limit": 20,
"offset": 0,
"transactions": [
{
"txId": "0x...",
"type": "contract_call",
"sender": "SP...",
"fee": "2500",
"nonce": 43,
"receiptTime": "2024-01-01T00:00:00.000Z",
"explorerUrl": "https://explorer.hiro.so/txid/0x...?chain=mainnet"
}
]
}
get-contract-info
获取智能合约信息,包括其 ABI。
bun run query/query.ts get-contract-info --contract-id <address.contract-name>
选项:
--contract-id(必需)— 格式为address.contract-name的合约 ID
输出:
{
"contractId": "SP...contract-name",
"network": "mainnet",
"txId": "0x...",
"blockHeight": 140000,
"functions": [
{ "name": "transfer", "access": "public", "args": [...], "outputs": {...} }
],
"variables": [...],
"maps": [...],
"fungibleTokens": [...],
"nonFungibleTokens": [...],
"explorerUrl": "https://explorer.hiro.so/txid/SP...contract-name?chain=mainnet"
}
get-contract-events
获取智能合约发出的事件。
bun run query/query.ts get-contract-events --contract-id <address.contract-name> [--limit 20] [--offset 0]
选项:
--contract-id(必需)— 格式为address.contract-name的合约 ID--limit(可选)— 最大结果数(默认值:20)--offset(可选)— 分页偏移量(默认值:0)
输出:
{
"contractId": "SP...contract-name",
"network": "mainnet",
"limit": 20,
"offset": 0,
"events": [...],
"explorerUrl": "https://explorer.hiro.so/txid/SP...contract-name?chain=mainnet"
}
get-network-status
获取 Stacks 网络的当前状态。
bun run query/query.ts get-network-status
输出:
{
"network": "mainnet",
"serverVersion": "stacks-node 2.4.0.0.0",
"status": "ready",
"chainTip": { "block_height": 145000, "block_hash": "0x..." },
"coreInfo": {
"peerVersion": 4026533888,
"stacksTipHeight": 145000,
"burnBlockHeight": 840000,
"networkId": 1
}
}
call-read-only
调用智能合约中的只读函数。
bun run query/query.ts call-read-only --contract-id <id> --function-name <name> [--args <json>] [--sender <address>]
选项:
--contract-id(必需)— 格式为address.contract-name的合约 ID--function-name(必需)— 只读函数的名称--args(可选)— 十六进制编码的 Clarity 值组成的 JSON 数组(默认值:[])--sender(可选)— 发送方地址(如果省略,则使用当前钱包地址或合约地址)
--args 选项接受十六进制编码的 Clarity 值组成的 JSON 数组。使用 @stacks/transactions 对值进行编码。例如,序列化为十六进制的 uintCV(1) 将是 "0100000000000000000000000000000001"。
输出:
{
"contractId": "SP...contract-name",
"functionName": "get-balance",
"network": "mainnet",
"okay": true,
"result": "0x0100000000000000000000000000000064",
"cause": null
}
备注
- 所有查询都使用 Hiro API(
api.mainnet.hiro.so或api.testnet.hiro.so) - 网络由
NETWORK环境变量控制(默认值:testnet) get-account-info和get-account-transactions会回退到当前钱包地址- 如果没有活动钱包,
call-read-only会回退到合约自身的地址作为发送方
评论
支持 Markdown