Logo

Avalanche RPC: Endpoints, Chain IDs, and Provider Selection

Resumen

This guide covers Avalanche RPC endpoints for the C-Chain, P-Chain, and X-Chain, including mainnet and Fuji testnet URLs, chain IDs, and how to choose a reliable RPC provider. It includes a decision checklist, evaluation criteria, and code examples to help developers integrate Avalanche RPC into their dApps.

Avalanche RPC Decision Checklist

Before integrating an Avalanche RPC endpoint, consider the following:

  • Which chain do you need? C-Chain (EVM-compatible smart contracts), P-Chain (validator/subnet management), or X-Chain (asset transfers)?
  • Mainnet or testnet? Use Fuji testnet for development and testing.
  • Public vs. private RPC? Public endpoints are rate-limited and may be unreliable for production. Private endpoints offer higher rate limits and dedicated resources.
  • Do you need archive data? Archive nodes provide historical state access for analytics or dApps that query past blocks.
  • WebSocket support? For real-time subscriptions (e.g., pending transactions), ensure the provider supports WebSocket endpoints.
  • Geographic distribution? Low latency requires endpoints close to your users or infrastructure.

Avalanche Network Architecture

Avalanche consists of three built-in blockchains, each with its own RPC interface:

  • C-Chain (Contract Chain): EVM-compatible, runs smart contracts. Uses standard Ethereum JSON-RPC methods.
  • P-Chain (Platform Chain): Coordinates validators, manages subnets, and staking. Has its own set of API methods.
  • X-Chain (Exchange Chain): Handles creation and transfer of digital assets (e.g., AVAX). Uses Avalanche-specific APIs.

Additionally, Avalanche supports subnets — custom blockchains with their own validator sets and virtual machines. Each subnet has its own RPC endpoint.

Avalanche RPC Endpoints

Mainnet

ChainRPC Endpoint (HTTP)WebSocket EndpointChain ID
C-Chainhttps://api.avax.network/ext/bc/C/rpcwss://api.avax.network/ext/bc/C/ws43114 (0xa86a)
P-Chainhttps://api.avax.network/ext/bc/PNot publicly available
X-Chainhttps://api.avax.network/ext/bc/XNot publicly available

Fuji Testnet

ChainRPC Endpoint (HTTP)WebSocket EndpointChain ID
C-Chainhttps://api.avax-test.network/ext/bc/C/rpcwss://api.avax-test.network/ext/bc/C/ws43113 (0xa869)
P-Chainhttps://api.avax-test.network/ext/bc/PNot publicly available
X-Chainhttps://api.avax-test.network/ext/bc/XNot publicly available

Note: The public API nodes (api.avax.network) have rate limits and may not be suitable for production workloads. For production, consider a dedicated RPC provider like OnFinality, which offers higher rate limits and dedicated nodes.

How to Choose an Avalanche RPC Provider

When evaluating RPC providers for Avalanche, use the following criteria:

CriterionWhat to checkWhy it matters
Endpoint coverageDoes the provider support C-Chain, P-Chain, X-Chain, and Fuji testnet?You may need multiple chains for your dApp.
Rate limitsWhat are the requests per second (RPS) limits?Public endpoints often throttle; production apps need higher limits.
Uptime and reliabilityIs there a service-level agreement (SLA)?Downtime can break your application.
LatencyWhere are the nodes geographically located?Lower latency improves user experience.
Archive dataDoes the provider offer archive nodes?Needed for historical queries and analytics.
WebSocket supportAre WebSocket endpoints available?Required for real-time updates.
Pricing modelPay-as-you-go, subscription, or free tier?Choose based on your budget and usage patterns.

For a deeper dive, see our guide on how to choose an RPC provider.

Making RPC Calls to Avalanche C-Chain

Since the C-Chain is EVM-compatible, you can use standard Ethereum libraries like ethers.js or web3.js. Below is an example using curl and ethers.js.

Using curl

curl -X POST https://api.avax.network/ext/bc/C/rpc \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_blockNumber",
    "params": [],
    "id": 1
  }'

Using ethers.js

const { ethers } = require("ethers");

const provider = new ethers.JsonRpcProvider("https://api.avax.network/ext/bc/C/rpc");

async function getBlockNumber() {
  const blockNumber = await provider.getBlockNumber();
  console.log("Current block number:", blockNumber);
}

getBlockNumber();

WebSocket Subscription Example

const { WebSocket } = require("ws");
const ws = new WebSocket("wss://api.avax.network/ext/bc/C/ws");

ws.on("open", function open() {
  ws.send(JSON.stringify({
    jsonrpc: "2.0",
    method: "eth_subscribe",
    params: ["newHeads"],
    id: 1
  }));
});

ws.on("message", function incoming(data) {
  console.log("New block:", JSON.parse(data));
});

Common Pitfalls and Troubleshooting

1. Rate Limiting

Public endpoints often return 429 Too Many Requests. Switch to a private RPC provider with higher limits.

2. Incorrect Chain ID

Ensure your wallet or dApp uses the correct chain ID: 43114 for mainnet, 43113 for Fuji testnet.

3. WebSocket Not Supported on P-Chain/X-Chain

Only the C-Chain supports WebSocket connections on the public API. For other chains, use HTTP polling.

4. Method Not Found

Some Ethereum methods (e.g., eth_getLogs) are supported on C-Chain but not on P-Chain or X-Chain. Check the AvalancheGo C-Chain RPC documentation for the full list.

Next Steps

Key Takeaways

  • Avalanche has three main chains: C-Chain (EVM), P-Chain (platform), and X-Chain (assets).
  • Public endpoints are suitable for testing but not for production due to rate limits.
  • Choose a provider based on endpoint coverage, rate limits, latency, and archive support.
  • Use standard Ethereum tools for C-Chain development; P-Chain and X-Chain require Avalanche-specific APIs.
  • Always verify chain IDs and WebSocket availability before integrating.

FAQ

What is the Avalanche C-Chain RPC URL?

The mainnet C-Chain RPC URL is https://api.avax.network/ext/bc/C/rpc. For Fuji testnet, use https://api.avax-test.network/ext/bc/C/rpc.

Does Avalanche support WebSocket RPC?

Yes, the C-Chain supports WebSocket at wss://api.avax.network/ext/bc/C/ws (mainnet) and wss://api.avax-test.network/ext/bc/C/ws (testnet).

What is the chain ID for Avalanche C-Chain?

Mainnet chain ID is 43114 (0xa86a). Fuji testnet chain ID is 43113 (0xa869).

Can I use Ethereum libraries with Avalanche?

Yes, the C-Chain is fully EVM-compatible, so you can use ethers.js, web3.js, Hardhat, and other Ethereum tools.

Where can I find a reliable Avalanche RPC provider?

OnFinality provides Avalanche RPC endpoints with higher rate limits and dedicated node options. Check our supported networks page for details.

Base de conocimiento RPC

Detalles RPC relacionados

Nunca te preocupes por la infraestructura nuevamente

OnFinality elimina la carga pesada de DevOps para que puedas construir de forma más inteligente y rápida.

Comenzar