Ethereum RPC 快速开始 - ERPC
Ethereum RPC 快速开始
本指南将带您从零开始,使用 ERPC 获取您的第一个 Ethereum JSON-RPC 响应。
1. 获取 API key
您可以在 ERPC Web Dashboard 获取和查看 API key。
已经在 Solana 上使用 ERPC 了吗?您可以直接使用与 Solana 相同的 RPC key。
2. 发送您的第一个请求
将 API key 放入
api-key 参数,以 HTTP POST 方式发送 JSON-RPC 2.0 请求: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"
}'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"
}'响应会以十六进制返回最新区块号:
json
{ "jsonrpc": "2.0", "id": 1, "result": "0x..." }{ "jsonrpc": "2.0", "id": 1, "result": "0x..." }您可以使用
eth_chainId 确认该端点所服务的链: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_chainId"
}'curl https://edge.erpc.global/eth?api-key=<YOUR_API_KEY> --header 'Content-Type: application/json' --data '{
"jsonrpc":"2.0","id":1,
"method":"eth_chainId"
}'3. 通过 WebSocket 订阅
WebSocket 端点支持标准的
eth_subscribe 订阅: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"]}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"]}有关可用的订阅类型,请参阅下方链接的官方 Ethereum JSON-RPC 文档。
4. 批量请求
您可以在一次 HTTP 请求中发送最多 256 个 JSON-RPC 调用。批次中的每次调用都会作为单独的调用计量。
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"},
{"jsonrpc":"2.0","id":2,"method":"eth_gasPrice"}
]'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"},
{"jsonrpc":"2.0","id":2,"method":"eth_gasPrice"}
]'后续步骤
- 端点、计量与状态码:Ethereum RPC 端点文档
- 包含请求和响应格式的完整方法列表:Ethereum RPC API 参考
- 官方 Ethereum JSON-RPC 文档:https://ethereum.org/en/developers/docs/apis/json-rpc/






