Ethereum RPC - Guida rapida

Ethereum RPC - Guida rapida

Questa guida ti accompagna da zero alla tua prima risposta Ethereum 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? Puoi usare la stessa chiave RPC di Solana.

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/eth?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 in esadecimale:
json
{ "jsonrpc": "2.0", "id": 1, "result": "0x..." }
Puoi verificare quale chain serve l'endpoint con eth_chainId:
bash
curl https://edge.erpc.global/eth?api-key=<YOUR_API_KEY> --header 'Content-Type: application/json' --data '{
  "jsonrpc":"2.0","id":1,
  "method":"eth_chainId"
}'

3. Sottoscrivi tramite WebSocket

L'endpoint WebSocket accetta sottoscrizioni eth_subscribe standard:
bash
wscat -c "wss://edge.erpc.global/eth?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 Ethereum JSON-RPC collegata qui sotto.

4. Richieste in batch

Puoi inviare fino a 256 chiamate JSON-RPC in un'unica richiesta HTTP. Ogni chiamata in un batch viene misurata come chiamata a sé stante.
bash
curl https://edge.erpc.global/eth?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