Avalanche RPC เริ่มต้นใช้งานอย่างรวดเร็ว | ERPC
เริ่มต้นใช้งานอย่างรวดเร็วกับ Avalanche RPC
คู่มือนี้จะพาคุณจากศูนย์ไปสู่การตอบกลับ Avalanche JSON-RPC ครั้งแรกของคุณด้วย ERPC.
1. รับ API Key ของคุณ
คุณสามารถสร้างและตรวจสอบ API key ของคุณได้ใน ERPC Web Dashboard: ERPC Web Dashboard
ใช้ ERPC สำหรับ Solana หรือ Ethereum อยู่แล้วใช่ไหม? คุณสามารถใช้ RPC key เดียวกันได้.
2. ส่ง Request แรกของคุณ
ส่ง request JSON-RPC 2.0 แบบ HTTP POST โดยใส่ API key ของคุณในพารามิเตอร์
api-key: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..." }คุณสามารถตรวจสอบว่า endpoint นี้ให้บริการ chain ใดได้ด้วย
eth_chainId. ผลลัพธ์คือ 0xa86a — 43114 ซึ่งเป็น chain ID ของ Avalanche C-Chain mainnet: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"
}'endpoint เดียวกันนี้ยังให้บริการ native API ของ Avalanche ด้วย. Upstream API ถูกเลือกตามชื่อ method ที่ตรงกันทุกประการ ดังนั้นคำสั่งเรียกของ X-Chain (
avm.*) และ P-Chain (platform.*) จึงไม่ต้องใช้ path หรือ host เพิ่มเติม: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 endpoint รองรับ subscription แบบ
eth_subscribe มาตรฐานของ C-Chain: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"]}สำหรับประเภท subscription ที่รองรับ โปรดดูเอกสาร Avalanche C-Chain ทางการที่ลิงก์ไว้ด้านล่าง.
4. Batch Requests
คุณสามารถส่งคำสั่งเรียก JSON-RPC ได้สูงสุด 256 รายการในหนึ่ง HTTP request สำหรับ method EVM ของ C-Chain. แต่ละคำสั่งเรียกในหนึ่ง batch จะถูกวัดเป็นคำสั่งเรียกแยกกัน.
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"}
]'ขั้นตอนถัดไป
- Endpoint, การวัดผลการใช้งาน และ status code: เอกสาร Avalanche RPC Endpoint
- รายการ method ทั้งหมดพร้อมรูปแบบ request และ response: ข้อมูลอ้างอิง Avalanche RPC API
- เอกสาร Avalanche C-Chain ทางการ: https://build.avax.network/docs/rpcs/c-chain






