---
title: "ERPC Ethereum RPC 快速開始"
description: "了解如何透過 ERPC 取得 API key、以 HTTP 傳送您的第一個 Ethereum JSON-RPC 請求，並透過 WebSocket 訂閱事件。"
canonical: "https://erpc.global/zh-tw/doc/ethereum-rpc/quickstart/"
locale: "zh-tw"
---

# ERPC Ethereum RPC 快速開始

## Ethereum RPC 快速開始

本指南將帶您從零開始，使用 ERPC 取得您的第一個 Ethereum JSON-RPC 回應。

### 1. 取得 API key

您可以在 [ERPC Web Dashboard](https://dashboard.erpc.global/zh-tw) 上取得和檢視您的 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"
}'
```

回應會以十六進位返回最新區塊編號：

```json
{ "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"
}'
```

### 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"]}
```

關於可用的訂閱類型，請參閱下方連結的官方 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"}
]'
```

### 後續步驟

- 端點、計量與狀態碼：[Ethereum RPC 端點文件](https://erpc.global/zh-tw/doc/ethereum-rpc/general/)
- 包含請求與回應格式的完整方法清單：[Ethereum RPC API 參考](https://erpc.global/zh-tw/api-doc/ethereum/)
- 官方 Ethereum JSON-RPC 文件：[https://ethereum.org/en/developers/docs/apis/json-rpc/](https://ethereum.org/en/developers/docs/apis/json-rpc/)
