JSON-RPC
各链支持的 JSON-RPC 方法、CU 权重与错误码。
概述
每条受支持链上的 JSON-RPC 2.0 访问都通过 BlockVectra 网关计量。所有请求按 计算单位(CU) 计量,并按 key 进行限流。
- 入口:
POST /v1/{chain}/{api_key}(key 放在路径中)或POST /v1/{chain}(key 放在请求头中)。Robinhood Chain 的{chain}是robinhood_mainnet:https://dev-api.blockvectra.network/v1/robinhood_mainnet。同一个 API key 可用于所有已支持的链 - 协议:HTTP
POST,单个调用或批量(最多 100 个调用) - 计量:请求到达时,其全部 CU 开销立即计入该 key 的突发容量;每个被受理并得到应答的调用按该方法公布的 CU 权重计费,不计费的情况见错误码表的「是否计费」列。按小时账期结算扣费(向下取整为整单位,余数结转下一期,账期结束约 15 分钟后执行)
- 可用性:可用方法因链而异。Robinhood Chain 上为
eth_*、net_*、web3_*、debug_trace*(有部分例外,见下文)。其他链见支持的链。 - 以太坊(Beta):有自己的方法清单,只保留最近约 36 天的数据,见支持的链 → 以太坊。
接入方式
1. 申请 API Key
2. 调用 JSON-RPC
export BLOCKVECTRA_API_KEY=rgw_your_api_key
curl -X POST "https://dev-api.blockvectra.network/v1/robinhood_mainnet/$BLOCKVECTRA_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc": "2.0",
"method": "eth_blockNumber",
"params": [],
"id": 1
}'Key 传递方式(优先级顺序):
- URL 路径:
POST /v1/{chain}/{api_key} POST /v1/{chain}的请求头:x-api-key: {api_key}(如果非空,覆盖 Bearer)POST /v1/{chain}的请求头:Authorization: Bearer {api_key}
3. 处理 CU 成本
每个方法都有对应的 CU(计算单位)权重,请求的成本是其包含的所有调用权重之和。各方法权重与默认值见下方 CU 权重表;具体哪些错误会计费见错误码表的「是否计费」列。用量按账户、按小时账期汇总扣费,向下取整为整计费单位(1 计费单位 = 1000 CU),未满 1 单位的余数结转到下一期(跨期合计扣费等于 floor(累计 CU / 1000));结算在账期结束约 15 分钟后执行(例如上期结转 508 CU,本期消耗 2557 CU,合计 3065 CU,本期扣除 3 个计费单位,余数 65 CU 结转至下一期)。
常用调用示例
常用调用的完整示例。
日志查询(eth_getLogs)
按合约地址和 topic 过滤最近一段区块的日志——这里以 ERC-20 的 Transfer 事件(topic 为 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef)为例。eth_getLogs 的当前 CU 权重见下方CU 计量规则表;网关会拒绝任何超过该链 eth_getLogs 跨度上限的请求。Robinhood Chain 上该上限为 1000 个区块(-32602 eth_getLogs block range too large: max 1000 blocks);其他链见支持的链。
export BLOCKVECTRA_API_KEY=rgw_your_api_key
curl -X POST "https://dev-api.blockvectra.network/v1/robinhood_mainnet" \
-H 'Content-Type: application/json' \
-H "x-api-key: $BLOCKVECTRA_API_KEY" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getLogs",
"params": [{
"fromBlock": "0x45a2409",
"toBlock": "0x45a2609",
"address": "0x1111111111111111111111111111111111111111",
"topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]
}],
"id": 1
}'交易 Trace(debug_traceTransaction)
用 callTracer 追踪一笔交易的内部调用。debug_trace* 的当前 CU 权重见下方CU 计量规则表。和其他读状态的方法一样,目标区块若超出该链的近期状态窗口就会被拒绝(-32011)。Robinhood Chain 上窗口为链头减 900 个区块;其他链见支持的链。在提供 trace 的链上,历史 trace 请使用 Data API。
注意:待追踪的交易必须处于该链的近期状态窗口内(Robinhood Chain 上约最近 900 个区块,即仅数分钟);更早的交易会返回
-32011(historical state is not available beyond the most recent 900 blocks)。
export BLOCKVECTRA_API_KEY=rgw_your_api_key
curl -X POST "https://dev-api.blockvectra.network/v1/robinhood_mainnet" \
-H 'Content-Type: application/json' \
-H "x-api-key: $BLOCKVECTRA_API_KEY" \
-d '{
"jsonrpc": "2.0",
"method": "debug_traceTransaction",
"params": ["0xYOUR_TRANSACTION_HASH", {"tracer": "callTracer"}],
"id": 1
}'批量请求
把多个调用合并到一次请求里——不超过前文已经提到的批量上限(每个请求最多 100 个调用)。下面的示例在一次往返里读取区块高度、链 ID 与 gas 价格。
export BLOCKVECTRA_API_KEY=rgw_your_api_key
curl -X POST "https://dev-api.blockvectra.network/v1/robinhood_mainnet" \
-H 'Content-Type: application/json' \
-H "x-api-key: $BLOCKVECTRA_API_KEY" \
-d '[
{"jsonrpc": "2.0", "method": "eth_blockNumber", "params": [], "id": 1},
{"jsonrpc": "2.0", "method": "eth_chainId", "params": [], "id": 2},
{"jsonrpc": "2.0", "method": "eth_gasPrice", "params": [], "id": 3}
]'如果网关直接拒绝整个批量请求——余额不足、限流、突发容量超限,或超过 100 个调用(见下方错误码表)——它会返回一个单独的 JSON-RPC 错误对象而不是数组;此时 viem 的 batch: true 模式只会报出一个不透明的 UnknownRpcError,请改为单独重试一次调用以查看真实错误。
CU 计量规则
各 JSON-RPC 方法的计算单位 (CU) 权重。
解析规则
精确匹配 > 最长前缀模式(以 * 结尾)> 默认值
默认值: 10 CU
| 方法名 | 权重 (CU) |
|---|---|
eth_blockNumber | 1 |
eth_call | 15 |
eth_chainId | 1 |
eth_createAccessList | 20 |
eth_estimateGas | 20 |
eth_getBlockByNumber | 5 |
eth_getBlockReceipts | 10 |
eth_getLogs | 30 |
eth_getProof | 10 |
eth_sendRawTransaction | 30 |
eth_simulateV1 | 20 |
debug_trace* | 100 |
方法策略
可用方法因链而异,下面按链分别列出,其他说明见支持的链。只有匹配允许的方法名或模式的方法才可调用;其中一部分方法即使匹配了允许模式,仍会被显式拦截(返回 -32601 method not available)。
eth_getLogs 单次最大块跨度 1000 个区块;状态窗口 250000 个区块
允许的方法与模式
eth_blockNumbereth_calleth_chainIdeth_estimateGaseth_feeHistoryeth_gasPriceeth_getBalanceeth_getBlockByHasheth_getBlockByNumbereth_getBlockReceiptseth_getBlockTransactionCountByHasheth_getBlockTransactionCountByNumbereth_getCodeeth_getLogseth_getProofeth_getStorageAteth_getTransactionByBlockHashAndIndexeth_getTransactionByBlockNumberAndIndexeth_getTransactionByHasheth_getTransactionCounteth_getTransactionReceipteth_maxPriorityFeePerGaseth_sendRawTransactioneth_syncingnet_versionweb3_clientVersion
被拦截的方法
eth_newFiltereth_newBlockFiltereth_newPendingTransactionFiltereth_getFilterLogseth_getFilterChangeseth_uninstallFiltereth_subscribeeth_unsubscribe
eth_getLogs 单次最大块跨度 1000 个区块;状态窗口:完整历史
允许的方法与模式
eth_blockNumbereth_calleth_chainIdeth_estimateGaseth_feeHistoryeth_gasPriceeth_getBalanceeth_getBlockByHasheth_getBlockByNumbereth_getBlockReceiptseth_getBlockTransactionCountByHasheth_getBlockTransactionCountByNumbereth_getCodeeth_getLogseth_getProofeth_getStorageAteth_getTransactionByBlockHashAndIndexeth_getTransactionByBlockNumberAndIndexeth_getTransactionByHasheth_getTransactionCounteth_getTransactionReceipteth_maxPriorityFeePerGaseth_syncingnet_versionweb3_clientVersion
被拦截的方法
eth_newFiltereth_newBlockFiltereth_newPendingTransactionFiltereth_getFilterLogseth_getFilterChangeseth_uninstallFiltereth_subscribeeth_unsubscribe
eth_getLogs 单次最大块跨度 1000 个区块;状态窗口 900 个区块
允许的方法与模式
eth_*net_*web3_*debug_trace*
被拦截的方法
eth_newFiltereth_newBlockFiltereth_newPendingTransactionFiltereth_getFilterLogseth_getFilterChangeseth_uninstallFiltereth_subscribeeth_unsubscribe
限制:
- 批量:每个请求最多 100 个调用;同时受该 key 的 CU 突发容量限制,见下文。
- 请求体:最大 2 MiB
- CU 突发:每个 API key 均有 CU 令牌桶(
cu_per_sec补充速率、burst_cu突发容量——默认 100 CU/s、突发 400 CU;在控制台 Keys 表按 key 显示)。单个请求(包括整批 JSON-RPC 批量调用)的 CU 总开销若超过该 key 的突发容量,会被拒绝并返回-32022 request_exceeds_burst(request cost <N> CU exceeds burst capacity <M> CU);请拆分为更小的批次。
错误码表
完整的 JSON-RPC 错误码目录及其计费规则。
| 错误码 | 来源 | HTTP 状态码 | 消息 | 是否计费 |
|---|---|---|---|---|
| -32700 | BlockVectra | 200 | parse error | 否 |
| -32600 | BlockVectra | 200 | invalid request | 否 |
| -32600 | BlockVectra | 200 | batch too large: max <N> calls | 否 |
| -32600 | BlockVectra | 200 | invalid request: ambiguous member name | 否 |
| -32601 | BlockVectra | 200 | method not available: <method> | 否 |
| -32600 | BlockVectra | 404 | unknown chain | 否 |
| -32602 | BlockVectra | 200 | eth_getLogs block range too large: max <N> blocks | 否 |
| -32602 | BlockVectra | 200 | tracer not allowed | 否 |
| -32602 | BlockVectra | 200 | trace timeout not allowed | 否 |
| -32010 | BlockVectra | 200 | node is syncing; calls are temporarily unavailable | 否 |
| -32011 | BlockVectra | 200 | historical state is not available beyond the most recent <N> blocks | 否 |
| -32000 | BlockVectra | 200 | transaction not found | 否 |
| -32000 | BlockVectra | 200 | block not found | 否 |
| -32000 | BlockVectra | 200 | upstream response too large | 否 |
| -32005 | BlockVectra | 200 | gateway overloaded, retry later | 否 |
| -32005 | BlockVectra | 429 | rate limit exceeded | 否 |
| -32022 | BlockVectra | 429 | request cost <N> CU exceeds burst capacity <M> CU | 否 |
| -32022 | BlockVectra | 429 | request has <N> calls, exceeding the free-plan limit of <M> calls per second | 否 |
| -32603 | BlockVectra | 200 | upstream unavailable | 否 |
| -32603 | BlockVectra | 200 | no response from upstream | 否 |
| -32603 | BlockVectra | 200 | malformed upstream response | 否 |
| -32603 | BlockVectra | 200 | internal gateway error | 否 |
| -32020 | BlockVectra | 402 | insufficient balance | 否 |
| -32021 | BlockVectra | 503 | billing data temporarily unavailable | 否 |
| 4444 | 节点(原样透传) | 200 | pruned history unavailable | 否 |
| -32000 | 节点(原样透传) | 200 | historical state ... is not available | 否 |
| -32000 | 节点(原样透传) | 200 | old data not available due to pruning... | 否 |
| -32002 | 节点(原样透传) | 200 | <node message> | 否 |
| -32003 | 节点(原样透传) | 200 | <node message> | 否 |
| -32600 | 节点(原样透传) | 200 | <node message> | 否 |
| * | 节点(原样透传) | 200 | <node message> | 是 |
完整 OpenAPI 参考
完整的机器可读规范(含所有方法签名、请求与响应 schema 及交互式参数详情)见完整 OpenAPI 参考。