ERPC Avalanche RPC 快速開始
Avalanche RPC 快速開始
本指南將帶您從零開始,使用 ERPC 取得您的第一個 Avalanche JSON-RPC 回應。
1. 取得 API key
您可以在 ERPC Web Dashboard 上取得和檢視您的 API key。
已經在 Solana 或 Ethereum 上使用 ERPC 了嗎?您可以直接使用相同的 RPC key。
2. 傳送您的第一個請求
將 API key 放入
api-key 參數,以 HTTP POST 方式傳送 JSON-RPC 2.0 請求:bash
curl https://edge.erpc.global/ava?api-key=<YOUR_API_KEY> --header 'Content-Type: application/json' --data '{
"jsonrpc":"2.0","id":1,
"method":"eth_blockNumber"
}'curl https://edge.erpc.global/ava?api-key=<YOUR_API_KEY> --header 'Content-Type: application/json' --data '{
"jsonrpc":"2.0","id":1,
"method":"eth_blockNumber"
}'回應會以十六進位返回最新的 C-Chain 區塊編號:
json
{ "jsonrpc": "2.0", "id": 1, "result": "0x..." }{ "jsonrpc": "2.0", "id": 1, "result": "0x..." }您可以使用
eth_chainId 確認該端點所服務的鏈。結果為 0xa86a — 即 43114,也就是 Avalanche C-Chain 主網的鏈 ID:bash
curl https://edge.erpc.global/ava?api-key=<YOUR_API_KEY> --header 'Content-Type: application/json' --data '{
"jsonrpc":"2.0","id":1,
"method":"eth_chainId"
}'curl https://edge.erpc.global/ava?api-key=<YOUR_API_KEY> --header 'Content-Type: application/json' --data '{
"jsonrpc":"2.0","id":1,
"method":"eth_chainId"
}'同一端點還提供 Avalanche 原生 API。上游 API 由精確的方法名稱決定,因此 X-Chain(
avm.*) 和 P-Chain(platform.*) 呼叫無需額外的路徑或主機:bash
curl https://edge.erpc.global/ava?api-key=<YOUR_API_KEY> --header 'Content-Type: application/json' --data '{
"jsonrpc":"2.0","id":1,
"method":"platform.getHeight",
"params":{}
}'curl https://edge.erpc.global/ava?api-key=<YOUR_API_KEY> --header 'Content-Type: application/json' --data '{
"jsonrpc":"2.0","id":1,
"method":"platform.getHeight",
"params":{}
}'3. 透過 WebSocket 訂閱
WebSocket 端點支援標準的 C-Chain
eth_subscribe 訂閱:bash
wscat -c "wss://edge.erpc.global/ava?api-key=<YOUR_API_KEY>"
# After connected, send:
{"jsonrpc":"2.0","id":1,"method":"eth_subscribe","params":["newHeads"]}wscat -c "wss://edge.erpc.global/ava?api-key=<YOUR_API_KEY>"
# After connected, send:
{"jsonrpc":"2.0","id":1,"method":"eth_subscribe","params":["newHeads"]}關於可用的訂閱類型,請參閱下方連結的官方 Avalanche C-Chain 文件。
4. 批次請求
您可以在一次 HTTP 請求中為 C-Chain 的 EVM 方法傳送最多 256 個 JSON-RPC 呼叫。批次中的每次呼叫都會作為單獨的呼叫計量。
bash
curl https://edge.erpc.global/ava?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/ava?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"}
]'後續步驟
- 端點、計量與狀態碼:Avalanche RPC 端點文件
- 包含請求與回應格式的完整方法清單:Avalanche RPC API 參考
- 官方 Avalanche C-Chain 文件:https://build.avax.network/docs/rpcs/c-chain






