---
title: "Tài liệu Ethereum RPC Endpoint"
description: "Dùng ERPC làm Ethereum RPC endpoint độ trễ thấp cho HTTP JSON-RPC request và WebSocket subscription."
canonical: "https://erpc.global/vi/doc/ethereum-rpc/general/"
locale: "vi"
---

# Tài liệu Ethereum RPC Endpoint

## Tài liệu Ethereum RPC Endpoint

ERPC có thể được dùng làm Ethereum RPC endpoint cho HTTP JSON-RPC request và WebSocket subscription. Ethereum RPC là một phần trong các RPC API của ERPC, nằm trong Global Edge Blockchain Infrastructure của chúng tôi, và API key có thể được quản lý từ ERPC Web Dashboard.

Bạn có thể dùng cùng một RPC key như với Solana.

Thêm API key của bạn vào tham số 'api-key'.

### Endpoint

Gửi request JSON-RPC 2.0 dưới dạng HTTP POST đến:

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

Để nhận subscription, hãy kết nối qua WebSocket đến:

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

### Ví dụ

Đây là ví dụ về HTTP request.

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

Đây là ví dụ về WebSocket subscription.

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

Bạn có thể lấy và kiểm tra API key trên ERPC Web Dashboard: [ERPC Web Dashboard](https://dashboard.erpc.global/vi)

### Batch Request

Hỗ trợ batch JSON-RPC lên đến 256 lệnh gọi cho mỗi HTTP request, và notification JSON-RPC cũng được chấp nhận. Mỗi lệnh gọi trong một batch được tính phí như một lệnh gọi riêng.

### Đo lường mức sử dụng

Mỗi lệnh gọi tốn một lượng token cố định, tùy theo phương thức. Mỗi lệnh gọi trong một batch HTTP, cũng như mỗi lệnh gọi gửi qua kết nối WebSocket, đều được tính riêng. Với WebSocket, mỗi thông báo subscription bạn nhận được cũng tốn token. Trên trang [Sử dụng API](https://dashboard.erpc.global/vi/user/api-usage) của dashboard, mức sử dụng được hiển thị theo đơn vị credit, mỗi credit bằng một token.

Dù gửi qua HTTP hay WebSocket, mỗi lệnh gọi đều tốn số token như sau:

| Phương thức | Token mỗi lệnh gọi |
| --- | --- |
| 46 phương thức trong danh sách bên dưới | 42 |
| 18 phương thức trong danh sách bên dưới | 81 |
| `eth_getLogs`, `eth_getFilterLogs`, `eth_sendRawTransaction`, `eth_callMany`, `eth_simulateV1`, `txpool_status`, `txpool_inspect`, `txpool_contentFrom`, `debug_getRawReceipts` | 84 |
| 17 phương thức trong danh sách bên dưới | 162 |
| `trace_callMany`, `txpool_content` | 168 |
| `trace_replayBlockTransactions`, `trace_replayTransaction` | 324 |
| Các phương thức không có ở các dòng trên | 81, 162 hoặc 324 |

Khi ước tính lượng token, hãy tính mỗi lệnh gọi đến các phương thức ở dòng “81, 162 hoặc 324” là 324 token, tức là mức cao nhất trong ba mức.

Các phương thức sau tốn 42 token mỗi lệnh gọi:

- `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`

Các phương thức sau tốn 81 token mỗi lệnh gọi:

- `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`

Các phương thức sau tốn 162 token mỗi lệnh gọi:

- `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`

Mỗi thông báo subscription bạn nhận được qua WebSocket (`wss://edge.erpc.global/eth`) tốn 42 token. Thông báo subscription là message `eth_subscription` mà server gửi cho bạn sau khi bạn gọi `eth_subscribe`.

Mỗi message bạn gửi qua kết nối mà server không parse được thành lệnh gọi JSON-RPC cũng tốn 42 token.

Bạn có thể kiểm tra mức token hiện tại cho mỗi lệnh gọi trong [Tài liệu API Ethereum RPC](https://erpc.global/vi/api-doc/ethereum/).

### Phương thức được hỗ trợ

Endpoint này bao phủ các nhóm method JSON-RPC chuẩn của Ethereum — `eth_*`, `net_*`, `txpool_*`, và `web3_*` — bao gồm đọc tài khoản và block (`eth_getBalance`, `eth_getBlockByNumber`, `eth_getLogs`), luồng giao dịch (`eth_sendRawTransaction`, `eth_getTransactionReceipt`), dữ liệu phí (`eth_feeHistory`, `eth_maxPriorityFeePerGas`), mô phỏng lệnh gọi (`eth_call`, `eth_callMany`, `eth_simulateV1`), state proof (`eth_getProof`), filter (`eth_newFilter`, `eth_getFilterChanges`), kiểm tra txpool (`txpool_status`, `txpool_content`), và WebSocket subscription (`eth_subscribe`, `eth_unsubscribe`).

Để xem danh sách method đầy đủ với cấu trúc request và response, hãy xem [Tài liệu API Ethereum RPC](https://erpc.global/vi/api-doc/ethereum/).

### Mã trạng thái phản hồi

| Trạng thái HTTP | Ý nghĩa |
| --- | --- |
| 200 | Response JSON-RPC từ upstream. |
| 400 | Thiếu API key, hoặc request JSON-RPC không hợp lệ. |
| 401 | API key không được ủy quyền. |
| 429 | Bị giới hạn tốc độ. Header `retry-after` cho biết thời gian chờ tính bằng giây. |
| 502 | Không thể hoàn tất request RPC upstream. |
| 503 | Dịch vụ tạm thời không khả dụng. |

Kết nối WebSocket dùng `101` (chấp nhận nâng cấp giao thức) ngoài các mã ở trên.

### Phương thức Ethereum RPC và tài liệu

Để xem danh sách đầy đủ các phương thức chuẩn, tham số và đặc tả subscription, hãy tham khảo tài liệu chính thức. Tài liệu này bao gồm cả cách dùng HTTP và WebSocket.

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