DEV Community

Zhuoxin Sun
Zhuoxin Sun

Posted on • Originally published at onfinality.io

Avalanche RPC Guide: Endpoints, Chain IDs & Provider Selection

Summary

Avalanche is a high-throughput Layer 1 blockchain platform with a multi-chain architecture. Developers interact with Avalanche via JSON-RPC endpoints for the Contract Chain (C-Chain), Platform Chain (P-Chain), and Exchange Chain (X-Chain). This guide provides the official endpoint URLs, chain IDs, and a practical decision checklist to help you select a reliable Avalanche RPC provider for your project.

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

Chain RPC Endpoint (HTTP) WebSocket Endpoint Chain ID
C-Chain https://api.avax.network/ext/bc/C/rpc wss://api.avax.network/ext/bc/C/ws 43114 (0xa86a)
P-Chain https://api.avax.network/ext/bc/P Not publicly available
X-Chain https://api.avax.network/ext/bc/X Not publicly available

Fuji Testnet

Chain RPC Endpoint (HTTP) WebSocket Endpoint Chain ID
C-Chain https://api.avax-test.network/ext/bc/C/rpc wss://api.avax-test.network/ext/bc/C/ws 43113 (0xa869)
P-Chain https://api.avax-test.network/ext/bc/P Not publicly available
X-Chain https://api.avax-test.network/ext/bc/X Not 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:

Criterion What to check Why it matters
Endpoint coverage Does the provider support C-Chain, P-Chain, X-Chain, and Fuji testnet? You may need multiple chains for your dApp.
Rate limits What are the requests per second (RPS) limits? Public endpoints often throttle; production apps need higher limits.
Uptime and reliability Is there a service-level agreement (SLA)? Downtime can break your application.
Latency Where are the nodes geographically located? Lower latency improves user experience.
Archive data Does the provider offer archive nodes? Needed for historical queries and analytics.
WebSocket support Are WebSocket endpoints available? Required for real-time updates.
Pricing model Pay-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
  }'
Enter fullscreen mode Exit fullscreen mode

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();
Enter fullscreen mode Exit fullscreen mode

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));
});
Enter fullscreen mode Exit fullscreen mode

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.

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.

Related resources

Originally published at OnFinality.

Top comments (0)