Passa al contenuto principale

JSON-RPC — Namespace eth_

QoreChain implementa un'interfaccia JSON-RPC pienamente compatibile con EVM, che consente ai tool standard dell'ecosistema Ethereum (MetaMask, Hardhat, Foundry, ethers.js, web3.js) di interagire con la chain senza alcuna modifica.

Connessione​

TrasportoIndirizzo predefinito
HTTPhttp://localhost:8545
WebSocketws://localhost:8546
nota

L'interfaccia JSON-RPC EVM è servita dalla mainnet qorechain-vladi (chain ID EVM 9801, hex 0x2649, attiva sulla versione della chain v3.1.97) e dalla testnet qorechain-diana (chain ID EVM 9800, hex 0x2648). Gli indirizzi locali sopra riportati si applicano a un nodo eseguito in proprio; per l'accesso da remoto sostituiscili con l'endpoint mainnet o testnet del tuo provider.

Namespace supportati​

NamespaceDescrizione
eth_Metodi JSON-RPC Ethereum principali
web3_Metodi di utilità (versione client, hashing)
net_Metodi sullo stato della rete
txpool_Ispezione del pool delle transazioni
qor_Estensioni specifiche di QoreChain (vedi Namespace qor_)

Metodi eth_​

MetodoParametriDescrizione
eth_blockNumbernessunoRestituisce il numero dell'ultimo blocco
eth_getBalanceaddress, blockNumberRestituisce il saldo di un indirizzo in wei
eth_getTransactionCountaddress, blockNumberRestituisce il nonce (numero di transazioni) di un indirizzo
eth_sendRawTransactionsignedTxDataInvia una transazione firmata per la trasmissione
eth_callcallObject, blockNumberEsegue una chiamata in sola lettura sull'EVM
eth_estimateGascallObjectStima il gas necessario per una transazione
eth_getBlockByNumberblockNumber, fullTx (bool)Restituisce i dati del blocco per numero
eth_getTransactionByHashtxHashRestituisce i dati della transazione per hash
eth_getTransactionReceipttxHashRestituisce la ricevuta di una transazione minata
eth_getLogsfilterObjectRestituisce i log corrispondenti a un filtro
eth_chainIdnessunoRestituisce il chain ID (codificato in hex)
eth_gasPricenessunoRestituisce il prezzo del gas corrente in wei
eth_feeHistoryblockCount, newestBlock, rewardPercentilesRestituisce i dati storici sulle fee (EIP-1559)

Metodi web3_​

MetodoParametriDescrizione
web3_clientVersionnessunoRestituisce la stringa di versione del client
web3_sha3data (hex)Restituisce l'hash Keccak-256 dell'input

Metodi net_​

MetodoParametriDescrizione
net_versionnessunoRestituisce l'ID della rete
net_listeningnessunoRestituisce true se il nodo è in ascolto
net_peerCountnessunoRestituisce il numero di peer connessi (hex)

Configurazione​

Abilita e configura il server JSON-RPC in app.toml:

[json-rpc]
# Enable the JSON-RPC server
enable = true

# HTTP server address
address = "0.0.0.0:8545"

# WebSocket server address
ws-address = "0.0.0.0:8546"

# Enabled API namespaces
api = "eth,web3,net,txpool,qor"

# Maximum number of logs returned by eth_getLogs
filter-cap = 10000

# Maximum gas for eth_call and eth_estimateGas
gas-cap = 25000000

# EVM execution timeout
evm-timeout = "5s"

# Transaction fee cap (in QOR)
txfee-cap = 1

# Maximum open WebSocket connections
max-open-connections = 0

Esempi​

eth_blockNumber​

Richiesta:

curl -X POST http://localhost:8545 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_blockNumber",
"params": [],
"id": 1
}'

Risposta:

{
"jsonrpc": "2.0",
"id": 1,
"result": "0x53b35"
}

eth_chainId​

Richiesta:

curl -X POST http://localhost:8545 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_chainId",
"params": [],
"id": 2
}'

Risposta (mainnet qorechain-vladi, chain ID 9801):

{
"jsonrpc": "2.0",
"id": 2,
"result": "0x2649"
}

Sulla testnet qorechain-diana (chain ID 9800) questo metodo restituisce "0x2648".

eth_getBalance​

Richiesta:

curl -X POST http://localhost:8545 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_getBalance",
"params": ["0x742d35Cc6634C0532925a3b844Bc9e7595f2bD28", "latest"],
"id": 3
}'

Risposta:

{
"jsonrpc": "2.0",
"id": 3,
"result": "0x56bc75e2d63100000"
}

Connessione con ethers.js​

import { ethers } from "ethers";

const provider = new ethers.JsonRpcProvider("http://localhost:8545");

// Get latest block
const block = await provider.getBlockNumber();
console.log("Latest block:", block);

// Get balance
const balance = await provider.getBalance("0x742d35Cc6634C0532925a3b844Bc9e7595f2bD28");
console.log("Balance:", ethers.formatEther(balance), "QOR");
informazioni
  • Il chain ID viene restituito come stringa esadecimale. Convertilo in decimale per la configurazione del wallet — 0x2649 corrisponde a 9801 (mainnet), 0x2648 a 9800 (testnet).
  • Il pricing del gas segue il modello EIP-1559. Usa eth_feeHistory per stimare la base fee e la priority fee.
  • Tag di blocco accettati: "latest", "earliest", "pending", oppure un numero di blocco in hex.
  • Limitazioni sui filtri: eth_getLogs è limitato a filter-cap risultati per query (10.000 di default). Usa intervalli di blocchi più ristretti per set di dati di grandi dimensioni.