Avalanche RPC - Quickstart
Avalanche RPC - Quickstart
Ce guide vous accompagne de zéro jusqu'à votre première réponse Avalanche JSON-RPC avec ERPC.
1. Récupérez votre API key
Vous pouvez obtenir et vérifier votre API key sur le Dashboard Web ERPC : Dashboard Web ERPC
Vous utilisez déjà ERPC pour Solana ou Ethereum ? Vous pouvez utiliser la même RPC key.
2. Effectuez votre première requête
Envoyez une requête JSON-RPC 2.0 en tant que HTTP POST, avec votre API key dans le paramètre
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"
}'La réponse renvoie le dernier numéro de bloc de la C-Chain en hexadécimal :
json
{ "jsonrpc": "2.0", "id": 1, "result": "0x..." }{ "jsonrpc": "2.0", "id": 1, "result": "0x..." }Vous pouvez vérifier quelle chaîne l'endpoint dessert avec
eth_chainId. Le résultat est 0xa86a — 43114, le chain ID du mainnet Avalanche C-Chain :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"
}'Le même endpoint sert aussi les APIs natives d'Avalanche. L'API en amont est sélectionnée selon le nom exact de la méthode, de sorte que les appels X-Chain (
avm.*) et P-Chain (platform.*) n'ont besoin d'aucun chemin ni hôte supplémentaire :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. Abonnez-vous via WebSocket
L'endpoint WebSocket accepte les abonnements
eth_subscribe standard de la 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"]}Pour les types d'abonnement disponibles, consultez la documentation officielle Avalanche C-Chain en lien ci-dessous.
4. Requêtes en batch
Vous pouvez envoyer jusqu'à 256 appels JSON-RPC en une seule requête HTTP pour les méthodes EVM de la C-Chain. Chaque appel dans un batch est mesuré comme un appel à part entière.
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"}
]'Prochaines étapes
- Endpoints, mesure d'utilisation et codes de statut : Documentation de l'endpoint RPC Avalanche
- Liste complète des méthodes avec les formats de requête et de réponse : Référence de l'API Avalanche RPC
- Documentation officielle Avalanche C-Chain : https://build.avax.network/docs/rpcs/c-chain






