ERPC Ethereum RPC 快速開始
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/






