query-onchain-data by coinbase/agentic-wallet-skills
npx skills add https://github.com/coinbase/agentic-wallet-skills --skill query-onchain-data使用 CDP SQL API 查询 Base 上的链上数据(事件、交易、区块、转账)。查询通过 x402 执行,并按查询次数收费。
npx awal@2.0.3 status
如果钱包未通过身份验证,请参考 authenticate-wallet 技能。
npx awal@2.0.3 x402 pay https://x402.cdp.coinbase.com/platform/v2/data/query/run -X POST -d '{"sql": "<YOUR_QUERY>"}' --json
重要提示:始终对 -d 后的 JSON 字符串使用单引号,以防止 bash 变量扩展。
在构建命令之前,请验证输入以防止 shell 注入:
-d '{"sql": "..."}')。切勿对 -d 包装器使用双引号,因为这会使查询中的 $ 和反引号进行 shell 扩展。广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
0x 十六进制地址(^0x[0-9a-fA-F]{40}$)。拒绝任何包含 shell 元字符的值。不要将未经验证的用户输入传递给命令。
针对 base.events 的查询必须在索引字段上进行过滤,以避免全表扫描。索引字段如下:
| 索引字段 | 用途 |
|---|---|
event_signature | 按事件类型过滤。出于性能考虑,请使用此字段而非 event_name。 |
address | 按合约地址过滤。 |
block_timestamp | 按时间范围过滤。 |
请始终在 WHERE 子句中包含至少一个索引字段。 组合所有三个字段可获得最佳性能。
CoinbaseQL 是一种基于 ClickHouse 的 SQL 方言。支持的功能:
=, !=, <>, <, >, <=, >=, +, -, *, /, %, AND, OR, NOT, BETWEEN, IN, IS NULL, LIKECAST() 和 :: 语法均支持),子查询,使用 [] 的数组/映射索引,点表示法[...], 映射 {...}, 元组 (...)-> 语法的 lambda 函数来自智能合约交互的解码事件日志。这是大多数查询的主要表。
| 列 | 类型 | 描述 |
|---|---|---|
| log_id | String | 唯一的日志标识符 |
| block_number | UInt64 | 区块号 |
| block_hash | FixedString(66) | 区块哈希 |
| block_timestamp | DateTime64(3, 'UTC') | 区块时间戳(已索引) |
| transaction_hash | FixedString(66) | 交易哈希 |
| transaction_to | FixedString(42) | 交易接收方 |
| transaction_from | FixedString(42) | 交易发送方 |
| log_index | UInt32 | 区块内的日志索引 |
| address | FixedString(42) | 合约地址(已索引) |
| topics | Array(FixedString(66)) | 事件主题 |
| event_name | LowCardinality(String) | 解码后的事件名称 |
| event_signature | LowCardinality(String) | 事件签名(已索引 - 优先于 event_name) |
| parameters | Map(String, Variant(Bool, Int256, String, UInt256)) | 解码后的事件参数 |
| parameter_types | Map(String, String) | 参数的 ABI 类型 |
| action | Enum8('removed' = -1, 'added' = 1) | 已添加或已移除(重组) |
完整的交易数据。
| 列 | 类型 | 描述 |
|---|---|---|
| block_number | UInt64 | 区块号 |
| block_hash | String | 区块哈希 |
| transaction_hash | String | 交易哈希 |
| transaction_index | UInt64 | 区块中的索引 |
| from_address | String | 发送方地址 |
| to_address | String | 接收方地址 |
| value | String | 转移的价值(wei) |
| gas | UInt64 | Gas 限制 |
| gas_price | UInt64 | Gas 价格 |
| input | String | 输入数据 |
| nonce | UInt64 | 发送方 nonce |
| type | UInt64 | 交易类型 |
| max_fee_per_gas | UInt64 | EIP-1559 最大费用 |
| max_priority_fee_per_gas | UInt64 | EIP-1559 优先费用 |
| chain_id | UInt64 | 链 ID |
| v | String | 签名 v |
| r | String | 签名 r |
| s | String | 签名 s |
| is_system_tx | Bool | 系统交易标志 |
| max_fee_per_blob_gas | String | Blob gas 费用 |
| blob_versioned_hashes | Array(String) | Blob 哈希 |
| timestamp | DateTime | 区块时间戳 |
| action | Int8 | 已添加 (1) 或已移除 (-1) |
区块级别的元数据。
| 列 | 类型 | 描述 |
|---|---|---|
| block_number | UInt64 | 区块号 |
| block_hash | String | 区块哈希 |
| parent_hash | String | 父区块哈希 |
| timestamp | DateTime | 区块时间戳 |
| miner | String | 区块生产者 |
| nonce | UInt64 | 区块 nonce |
| sha3_uncles | String | 叔块哈希 |
| transactions_root | String | 交易默克尔根 |
| state_root | String | 状态默克尔根 |
| receipts_root | String | 收据默克尔根 |
| logs_bloom | String | 布隆过滤器 |
| gas_limit | UInt64 | 区块 Gas 限制 |
| gas_used | UInt64 | 区块中使用的 Gas |
| base_fee_per_gas | UInt64 | 基础 Gas 费用 |
| total_difficulty | String | 总链难度 |
| size | UInt64 | 区块大小(字节) |
| extra_data | String | 额外数据字段 |
| mix_hash | String | 混合哈希 |
| withdrawals_root | String | 提款根 |
| parent_beacon_block_root | String | 信标链父根 |
| blob_gas_used | UInt64 | 使用的 Blob gas |
| excess_blob_gas | UInt64 | 超额 Blob gas |
| transaction_count | UInt64 | 交易数量 |
| action | Int8 | 已添加 (1) 或已移除 (-1) |
SELECT
parameters['from'] AS sender,
parameters['to'] AS to,
parameters['value'] AS amount,
address AS token_address
FROM base.events
WHERE
event_signature = 'Transfer(address,address,uint256)'
AND address = '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913'
AND block_timestamp >= now() - INTERVAL 7 DAY
LIMIT 10
npx awal@2.0.3 x402 pay https://x402.cdp.coinbase.com/platform/v2/data/query/run -X POST -d '{"sql": "SELECT transaction_hash, to_address, value, gas, timestamp FROM base.transactions WHERE from_address = lower('\''0xYOUR_ADDRESS'\'') AND timestamp >= now() - INTERVAL 1 DAY LIMIT 10"}' --json
npx awal@2.0.3 x402 pay https://x402.cdp.coinbase.com/platform/v2/data/query/run -X POST -d '{"sql": "SELECT event_signature, count(*) as cnt FROM base.events WHERE address = lower('\''0xCONTRACT_ADDRESS'\'') AND block_timestamp >= now() - INTERVAL 1 HOUR GROUP BY event_signature ORDER BY cnt DESC LIMIT 20"}' --json
npx awal@2.0.3 x402 pay https://x402.cdp.coinbase.com/platform/v2/data/query/run -X POST -d '{"sql": "SELECT block_number, timestamp, transaction_count, gas_used FROM base.blocks ORDER BY block_number DESC LIMIT 1"}' --json
| 代币 | 地址 |
|---|---|
| USDC | 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 |
| WETH | 0x4200000000000000000000000000000000000006 |
base.events 查询中过滤索引字段(event_signature, address, block_timestamp)。SELECT * - 仅指定您需要的列。LIMIT 子句以限制结果大小。event_signature 而非 event_name 进行过滤 - 它已建立索引,速度更快。block_timestamp 的时间限制查询以缩小扫描范围。lower() 中 - 数据库存储小写地址,但用户可能提供带校验和(混合大小写)的地址。使用 address = lower('0xAbC...') 而不是 address = '0xAbC...'。Transfer(address,address,uint256), Approval(address,address,uint256), Swap(address,uint256,uint256,uint256,uint256,address)。npx awal@2.0.3 status 检查,参见 authenticate-wallet 技能)npx awal@2.0.3 balance 检查)awal auth login <email>,或参见 authenticate-wallet 技能fund 技能每周安装次数
542
代码仓库
GitHub 星标数
76
首次出现
2026年2月12日
安全审计
已安装于
codex404
opencode404
gemini-cli391
github-copilot379
openclaw367
kimi-cli363
Use the CDP SQL API to query onchain data (events, transactions, blocks, transfers) on Base. Queries are executed via x402 and are charged per query.
npx awal@2.0.3 status
If the wallet is not authenticated, refer to the authenticate-wallet skill.
npx awal@2.0.3 x402 pay https://x402.cdp.coinbase.com/platform/v2/data/query/run -X POST -d '{"sql": "<YOUR_QUERY>"}' --json
IMPORTANT : Always single-quote the -d JSON string to prevent bash variable expansion.
Before constructing the command, validate inputs to prevent shell injection:
-d '{"sql": "..."}'). Never use double quotes for the outer -d wrapper, as this enables shell expansion of $ and backticks within the query.0x hex addresses (^0x[0-9a-fA-F]{40}$). Reject any value containing shell metacharacters.Do not pass unvalidated user input into the command.
Queries against base.events MUST filter on indexed fields to avoid full table scans. The indexed fields are:
| Indexed Field | Use For |
|---|---|
event_signature | Filter by event type. Use this instead of event_name for performance. |
address | Filter by contract address. |
block_timestamp | Filter by time range. |
Always include at least one indexed field in your WHERE clause. Combining all three gives the best performance.
CoinbaseQL is a SQL dialect based on ClickHouse. Supported features:
=, !=, <>, <, >, <=, >=, +, -, *, /, , AND, OR, NOT, BETWEEN, IN, IS NULL, LIKEDecoded event logs from smart contract interactions. This is the primary table for most queries.
| Column | Type | Description |
|---|---|---|
| log_id | String | Unique log identifier |
| block_number | UInt64 | Block number |
| block_hash | FixedString(66) | Block hash |
| block_timestamp | DateTime64(3, 'UTC') | Block timestamp (INDEXED) |
| transaction_hash | FixedString(66) | Transaction hash |
| transaction_to | FixedString(42) | Transaction recipient |
| transaction_from | FixedString(42) | Transaction sender |
| log_index | UInt32 | Log index within block |
| address | FixedString(42) | Contract address () |
Complete transaction data.
| Column | Type | Description |
|---|---|---|
| block_number | UInt64 | Block number |
| block_hash | String | Block hash |
| transaction_hash | String | Transaction hash |
| transaction_index | UInt64 | Index in block |
| from_address | String | Sender address |
| to_address | String | Recipient address |
| value | String | Value transferred (wei) |
| gas | UInt64 | Gas limit |
| gas_price | UInt64 | Gas price |
| input | String |
Block-level metadata.
| Column | Type | Description |
|---|---|---|
| block_number | UInt64 | Block number |
| block_hash | String | Block hash |
| parent_hash | String | Parent block hash |
| timestamp | DateTime | Block timestamp |
| miner | String | Block producer |
| nonce | UInt64 | Block nonce |
| sha3_uncles | String | Uncles hash |
| transactions_root | String | Transactions merkle root |
| state_root | String | State merkle root |
| receipts_root | String |
SELECT
parameters['from'] AS sender,
parameters['to'] AS to,
parameters['value'] AS amount,
address AS token_address
FROM base.events
WHERE
event_signature = 'Transfer(address,address,uint256)'
AND address = '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913'
AND block_timestamp >= now() - INTERVAL 7 DAY
LIMIT 10
npx awal@2.0.3 x402 pay https://x402.cdp.coinbase.com/platform/v2/data/query/run -X POST -d '{"sql": "SELECT transaction_hash, to_address, value, gas, timestamp FROM base.transactions WHERE from_address = lower('\''0xYOUR_ADDRESS'\'') AND timestamp >= now() - INTERVAL 1 DAY LIMIT 10"}' --json
npx awal@2.0.3 x402 pay https://x402.cdp.coinbase.com/platform/v2/data/query/run -X POST -d '{"sql": "SELECT event_signature, count(*) as cnt FROM base.events WHERE address = lower('\''0xCONTRACT_ADDRESS'\'') AND block_timestamp >= now() - INTERVAL 1 HOUR GROUP BY event_signature ORDER BY cnt DESC LIMIT 20"}' --json
npx awal@2.0.3 x402 pay https://x402.cdp.coinbase.com/platform/v2/data/query/run -X POST -d '{"sql": "SELECT block_number, timestamp, transaction_count, gas_used FROM base.blocks ORDER BY block_number DESC LIMIT 1"}' --json
| Token | Address |
|---|---|
| USDC | 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 |
| WETH | 0x4200000000000000000000000000000000000006 |
event_signature, address, block_timestamp) in base.events queries.SELECT * - specify only the columns you need.LIMIT clause to bound result size.event_signature instead of event_name for filtering - it is indexed and much faster.block_timestamp to narrow the scan range.npx awal@2.0.3 status to check, see authenticate-wallet skill)npx awal@2.0.3 balance to check)awal auth login <email> first, or see authenticate-wallet skillfund skillWeekly Installs
542
Repository
GitHub Stars
76
First Seen
Feb 12, 2026
Security Audits
Gen Agent Trust HubWarnSocketPassSnykWarn
Installed on
codex404
opencode404
gemini-cli391
github-copilot379
openclaw367
kimi-cli363
DOCX文件创建、编辑与分析完整指南 - 使用docx-js、Pandoc和Python脚本
41,800 周安装
%CAST() and :: syntax), subqueries, array/map indexing with [], dot notation[...], Map {...}, Tuple (...)-> syntax| topics | Array(FixedString(66)) | Event topics |
| event_name | LowCardinality(String) | Decoded event name |
| event_signature | LowCardinality(String) | Event signature (INDEXED - prefer over event_name) |
| parameters | Map(String, Variant(Bool, Int256, String, UInt256)) | Decoded event parameters |
| parameter_types | Map(String, String) | ABI types for parameters |
| action | Enum8('removed' = -1, 'added' = 1) | Added or removed (reorg) |
| Input data |
| nonce | UInt64 | Sender nonce |
| type | UInt64 | Transaction type |
| max_fee_per_gas | UInt64 | EIP-1559 max fee |
| max_priority_fee_per_gas | UInt64 | EIP-1559 priority fee |
| chain_id | UInt64 | Chain ID |
| v | String | Signature v |
| r | String | Signature r |
| s | String | Signature s |
| is_system_tx | Bool | System transaction flag |
| max_fee_per_blob_gas | String | Blob gas fee |
| blob_versioned_hashes | Array(String) | Blob hashes |
| timestamp | DateTime | Block timestamp |
| action | Int8 | Added (1) or removed (-1) |
| Receipts merkle root |
| logs_bloom | String | Bloom filter |
| gas_limit | UInt64 | Block gas limit |
| gas_used | UInt64 | Gas used in block |
| base_fee_per_gas | UInt64 | Base fee per gas |
| total_difficulty | String | Total chain difficulty |
| size | UInt64 | Block size in bytes |
| extra_data | String | Extra data field |
| mix_hash | String | Mix hash |
| withdrawals_root | String | Withdrawals root |
| parent_beacon_block_root | String | Beacon chain parent root |
| blob_gas_used | UInt64 | Blob gas used |
| excess_blob_gas | UInt64 | Excess blob gas |
| transaction_count | UInt64 | Number of transactions |
| action | Int8 | Added (1) or removed (-1) |
lower() - the database stores lowercase addresses but users may provide checksummed (mixed-case) addresses. Use address = lower('0xAbC...') not address = '0xAbC...'.Transfer(address,address,uint256), Approval(address,address,uint256), Swap(address,uint256,uint256,uint256,uint256,address).