Avalanche RPC - Guida rapida
Avalanche RPC - Guida rapida
Questa guida ti accompagna da zero alla tua prima risposta Avalanche JSON-RPC con ERPC.
1. Ottieni la tua chiave API
Puoi ottenere e verificare la tua chiave API sulla ERPC Web Dashboard: ERPC Web Dashboard
Usi già ERPC per Solana o Ethereum? Puoi usare la stessa chiave RPC.
2. Effettua la tua prima richiesta
Invia una richiesta JSON-RPC 2.0 come HTTP POST, con la tua chiave API nel parametro
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 risposta restituisce l'ultimo numero di blocco della C-Chain in esadecimale:
json
{ "jsonrpc": "2.0", "id": 1, "result": "0x..." }{ "jsonrpc": "2.0", "id": 1, "result": "0x..." }Puoi verificare quale chain serve l'endpoint con
eth_chainId. Il risultato è 0xa86a — cioè 43114, il chain ID della 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"
}'Lo stesso endpoint serve anche le API native di Avalanche. L'API upstream viene selezionata in base al nome esatto del metodo, quindi le chiamate X-Chain (
avm.*) e P-Chain (platform.*) non richiedono un percorso o un host aggiuntivo: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. Sottoscrivi tramite WebSocket
L'endpoint WebSocket accetta sottoscrizioni
eth_subscribe standard della 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"]}Per i tipi di sottoscrizione disponibili, consulta la documentazione ufficiale di Avalanche C-Chain collegata qui sotto.
4. Richieste in batch
Puoi inviare fino a 256 chiamate JSON-RPC in un'unica richiesta HTTP per i metodi EVM della C-Chain. Ogni chiamata in un batch viene misurata come chiamata a sé stante.
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"}
]'Prossimi passi
- Endpoint, utilizzo dei token e codici di stato: Documentazione dell'endpoint RPC di Avalanche
- Elenco completo dei metodi con i formati di richiesta e risposta: Riferimento API Avalanche RPC
- Documentazione ufficiale di Avalanche C-Chain: https://build.avax.network/docs/rpcs/c-chain






