---
title: "Ethereum RPC 端点文档 - ERPC"
description: "了解如何将 ERPC 用作低延迟的 Ethereum RPC 端点，以处理 HTTP JSON-RPC 请求和 WebSocket 订阅。"
canonical: "https://erpc.global/zh/doc/ethereum-rpc/general/"
locale: "zh"
---

# Ethereum RPC 端点文档 - ERPC

## Ethereum RPC 端点文档

将 ERPC 用作您的 Ethereum RPC 端点，处理 HTTP JSON-RPC 请求和 WebSocket 订阅。Ethereum RPC 是 ERPC 在 Global Edge Blockchain Infrastructure 中提供的 RPC APIs 之一，API key 可以在 ERPC Web Dashboard 中管理。

您可以直接使用与 Solana 相同的 RPC key。

请将您的 API key 添加到 'api-key' 参数中。

### 端点

将 JSON-RPC 2.0 请求以 HTTP POST 方式发送至：

```text
https://edge.erpc.global/eth?api-key=<YOUR_API_KEY>
```

如需订阅，请通过 WebSocket 连接至：

```text
wss://edge.erpc.global/eth?api-key=<YOUR_API_KEY>
```

### 示例

以下是 HTTP 请求示例。

```bash
curl https://edge.erpc.global/eth?api-key=<YOUR_API_KEY> --header 'Content-Type: application/json' --data '{
  "jsonrpc":"2.0","id":1,
  "method":"eth_blockNumber"
}'
```

以下是 WebSocket 订阅示例。

```bash
wscat -c "wss://edge.erpc.global/eth?api-key=<YOUR_API_KEY>"
# After connected, send:
{"jsonrpc":"2.0","id":1,"method":"eth_subscribe","params":["newHeads"]}
```

您可以在 [ERPC Web Dashboard](https://dashboard.erpc.global/zh) 获取和查看 API key。

### 批量请求

每次 HTTP 请求最多支持 256 个 JSON-RPC 批量调用，同时也接受 JSON-RPC notification。批次中的每次调用都会作为单独的调用计量。

### 用量计量

每次调用消耗的 token 数量由所调用的方法决定，且固定不变。HTTP 批量请求中的每个调用，以及通过 WebSocket 连接发送的每个调用，都按一次调用单独计费。使用 WebSocket 时，每收到一条订阅通知也会消耗 token。在 ERPC Web Dashboard 的 [API 使用情况](https://dashboard.erpc.global/zh/user/api-usage) 页面中，每个 token 计为一个积分。

通过 HTTP 和 WebSocket 发送的调用，每次消耗的 token 如下：

| 方法 | 每次调用的 token |
| --- | --- |
| 下方列表中的 46 个方法 | 42 |
| 下方列表中的 18 个方法 | 81 |
| `eth_getLogs`, `eth_getFilterLogs`, `eth_sendRawTransaction`, `eth_callMany`, `eth_simulateV1`, `txpool_status`, `txpool_inspect`, `txpool_contentFrom`, `debug_getRawReceipts` | 84 |
| 下方列表中的 17 个方法 | 162 |
| `trace_callMany`, `txpool_content` | 168 |
| `trace_replayBlockTransactions`, `trace_replayTransaction` | 324 |
| 除以上各行外的所有方法 | 81、162 或 324 |

估算用量时，请将“81、162 或 324”这一行中的方法按三个值中最高的 324 计算。

以下方法每次调用消耗 42 token：

- `eth_*` (41): `eth_accounts`, `eth_baseFee`, `eth_blobBaseFee`, `eth_blockNumber`, `eth_call`, `eth_capabilities`, `eth_chainId`, `eth_createAccessList`, `eth_estimateGas`, `eth_feeHistory`, `eth_gasPrice`, `eth_getAccount`, `eth_getBalance`, `eth_getBlockByHash`, `eth_getBlockByNumber`, `eth_getBlockReceipts`, `eth_getBlockTransactionCountByHash`, `eth_getBlockTransactionCountByNumber`, `eth_getCode`, `eth_getFilterChanges`, `eth_getProof`, `eth_getRawTransactionByHash`, `eth_getStorageAt`, `eth_getTransactionByBlockHashAndIndex`, `eth_getTransactionByBlockNumberAndIndex`, `eth_getTransactionByHash`, `eth_getTransactionBySenderAndNonce`, `eth_getTransactionCount`, `eth_getTransactionReceipt`, `eth_getUncleCountByBlockHash`, `eth_getUncleCountByBlockNumber`, `eth_maxPriorityFeePerGas`, `eth_newBlockFilter`, `eth_newFilter`, `eth_newPendingTransactionFilter`, `eth_signTransaction`, `eth_submitWork`, `eth_subscribe`, `eth_syncing`, `eth_uninstallFilter`, `eth_unsubscribe`
- `net_*` (3): `net_listening`, `net_peerCount`, `net_version`
- `web3_*` (2): `web3_clientVersion`, `web3_sha3`

以下方法每次调用消耗 81 token：

- `eth_*` (18): `eth_cancelPrivateTransaction`, `eth_coinbase`, `eth_getHeaderByNumber`, `eth_getRawTransactionByBlockHashAndIndex`, `eth_getRawTransactionByBlockNumberAndIndex`, `eth_getUncleByBlockHashAndIndex`, `eth_getUncleByBlockNumberAndIndex`, `eth_getUserOperationReceipt`, `eth_getWork`, `eth_hashrate`, `eth_mining`, `eth_pendingTransactions`, `eth_protocolVersion`, `eth_sendPrivateTransaction`, `eth_sendTransaction`, `eth_sign`, `eth_submitHashRate`, `eth_submitHashrate`

以下方法每次调用消耗 162 token：

- `debug_*` (11): `debug_gcStats`, `debug_getBadBlocks`, `debug_getBlockReceipts`, `debug_getTrieFlushInterval`, `debug_storageRangeAt`, `debug_traceBlock`, `debug_traceBlockByHash`, `debug_traceBlockByNumber`, `debug_traceCall`, `debug_traceCallMany`, `debug_traceTransaction`
- `trace_*` (6): `trace_block`, `trace_call`, `trace_filter`, `trace_get`, `trace_rawTransaction`, `trace_transaction`

通过 WebSocket（`wss://edge.erpc.global/eth`）收到的每条订阅通知消耗 42 token。订阅通知是指您通过 `eth_subscribe` 创建订阅后，服务器推送的 `eth_subscription` 消息。

您通过连接发送的、无法解析为 JSON-RPC 调用的每条消息，也消耗 42 token。

您可以在 [Ethereum RPC API 参考](https://erpc.global/zh/api-doc/ethereum/) 中查看当前的单次调用 token 费率。

### 支持的方法

该端点覆盖标准 Ethereum JSON-RPC 方法族 — `eth_*`、`net_*`、`txpool_*`、`web3_*` — 包括账户与区块读取（`eth_getBalance`、`eth_getBlockByNumber`、`eth_getLogs`）、交易流程（`eth_sendRawTransaction`、`eth_getTransactionReceipt`）、手续费数据（`eth_feeHistory`、`eth_maxPriorityFeePerGas`）、调用模拟（`eth_call`、`eth_callMany`、`eth_simulateV1`）、状态证明（`eth_getProof`）、过滤器（`eth_newFilter`、`eth_getFilterChanges`）、txpool 检查（`txpool_status`、`txpool_content`）以及 WebSocket 订阅（`eth_subscribe`、`eth_unsubscribe`）。

如需包含请求和响应格式的完整方法列表，请参阅 [Ethereum RPC API 参考](https://erpc.global/zh/api-doc/ethereum/)。

### 响应状态码

| HTTP 状态码 | 含义 |
| --- | --- |
| 200 | 上游 JSON-RPC 响应 |
| 400 | 缺少 API key，或 JSON-RPC 请求无效 |
| 401 | API key 未获授权 |
| 429 | 已被限速。`retry-after` 响应头给出等待秒数 |
| 502 | 上游 RPC 请求无法完成 |
| 503 | 服务暂时不可用 |

WebSocket 连接除上述状态码外，还会使用 `101`（协议升级已接受）。

### Ethereum RPC 方法和文档

有关标准方法、参数和订阅规范的完整列表，请参阅官方文档。文档涵盖 HTTP 和 WebSocket 的使用方式。

[https://ethereum.org/en/developers/docs/apis/json-rpc/](https://ethereum.org/en/developers/docs/apis/json-rpc/)
