ERPC Ethereum RPC 端點文件

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 方式傳送至:
endpoint
https://edge.erpc.global/eth?api-key=<YOUR_API_KEY>
如需訂閱,請透過 WebSocket 連線至:
endpoint
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 上取得和檢視您的 API key。

批次請求

每次 HTTP 請求最多支援 256 個 JSON-RPC 批次呼叫,同時也接受 JSON-RPC notification。批次中的每次呼叫都會作為單獨的呼叫計量。

用量計量

每次呼叫消耗的 token 數為固定值,取決於所呼叫的方法。HTTP 批次請求中的每個呼叫,以及透過 WebSocket 連線送出的每個呼叫,都會各自計為一次呼叫。使用 WebSocket 時,您每收到一則訂閱通知,也會消耗 token。在 ERPC Web Dashboard 的 API 使用情況 頁面中,token 會以「Credit」顯示,每個 token 即一個 Credit。
透過 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_getRawReceipts84
下方清單中的 17 個方法162
trace_callMany, txpool_content168
trace_replayBlockTransactions, trace_replayTransaction324
上方各列以外的所有方法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 參考 中查看目前的單次呼叫 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 參考。

回應狀態碼

HTTP 狀態碼意義
200上游 JSON-RPC 回應
400缺少 API key,或 JSON-RPC 請求無效
401API key 未獲授權
429已被限速。retry-after 標頭提供等待秒數
502上游 RPC 請求無法完成
503服務暫時無法使用
WebSocket 連線除上述狀態碼外,還會使用 101(通訊協定升級已接受)。

Ethereum RPC 方法和文件

有關標準方法、參數和訂閱規範的完整列表,請參閱官方文件。文件涵蓋 HTTP 和 WebSocket 的使用方式。