ERPC Avalanche RPC クイックスタート
Avalanche RPC クイックスタート
このガイドでは、ゼロの状態から ERPC で最初の Avalanche JSON-RPC レスポンスを受け取るまでの手順を解説します。
1. API key を取得する
API key は ERPC Web Dashboard 上にて取得、確認いただけます: ERPC Web Dashboard
すでに ERPC を Solana または Ethereum で利用中ですか?同じ RPC キーを利用できます。
2. 最初のリクエストを送信する
api-key パラメータに API key を指定し、JSON-RPC 2.0 リクエストを HTTP POST で送信します。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 ブロック番号が 16 進数で返されます。
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.*)の呼び出しに追加の 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 エンドポイントは標準の 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. バッチリクエスト
C-Chain の EVM メソッドでは、1 回の HTTP リクエストで最大 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






