DEV Community

OnFinality
OnFinality

Posted on Originally published at onfinality.io

Polygon RPC Endpoint: Chain Settings & Connection Guide

Quick decision guide

Before you copy an endpoint into your dApp or wallet, decide which type of access fits your workload. A public endpoint is fine for prototyping, hackathon demos, or low-traffic tools. If you are building a production application, an indexer, or a service that depends on consistent throughput, you should evaluate a dedicated RPC node or a managed RPC provider with a service-level agreement.

  • Prototyping or learning: use the public endpoint and expect rate limits.
  • Production dApp: use a managed RPC provider with a dedicated or high-throughput plan.
  • High-frequency trading or data-heavy workloads: consider a dedicated node to avoid noisy-neighbor effects.

For a deeper comparison of RPC providers, see our guide on choosing an RPC provider.

Polygon chain settings at a glance

Polygon is an EVM-compatible sidechain that settles on Ethereum. The mainnet and the Amoy testnet share the same RPC interface, so you can switch between them by changing the endpoint and chain ID.

Property Polygon Mainnet Polygon Amoy Testnet
Network name Polygon Mainnet Amoy
Chain ID 137 (0x89) 80002
Native currency POL POL
RPC endpoint https://polygon.api.onfinality.io/public https://polygon-amoy.api.onfinality.io/public
WebSocket endpoint wss://polygon.api.onfinality.io/public wss://polygon-amoy.api.onfinality.io/public
Block explorer https://polygonscan.com https://amoy.polygonscan.com

Note: The public endpoints are free to use but may have rate limits. For production, consider a dedicated node or a paid RPC plan.

How to connect to Polygon RPC

You can interact with the Polygon RPC endpoint using any standard JSON-RPC client. Here is a basic curl example to get the latest block number:

curl https://polygon.api.onfinality.io/public \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
Enter fullscreen mode Exit fullscreen mode

For JavaScript applications, use ethers.js or viem. Here is an example with ethers:

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

const provider = new ethers.JsonRpcProvider("https://polygon.api.onfinality.io/public");

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

getBlockNumber();
Enter fullscreen mode Exit fullscreen mode

If you need real-time updates, use the WebSocket endpoint:

const { WebSocket } = require("ws");
const ws = new WebSocket("wss://polygon.api.onfinality.io/public");

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

ws.on("message", (data) => {
  console.log("New block:", JSON.parse(data));
});
Enter fullscreen mode Exit fullscreen mode

Adding Polygon to MetaMask

To add Polygon to MetaMask manually, use the following settings:

  • Network name: Polygon Mainnet
  • New RPC URL: https://polygon.api.onfinality.io/public
  • Chain ID: 137
  • Currency symbol: POL
  • Block explorer URL: https://polygonscan.com

For the Amoy testnet, use chain ID 80002 and the explorer https://amoy.polygonscan.com.

Public vs. dedicated RPC: what to consider

Public RPC endpoints are convenient but come with trade-offs. They are shared across many users, so they can be rate-limited or slow during peak times. For production applications, you need predictable performance and reliability.

Factor Public RPC Dedicated RPC
Cost Free Paid
Rate limits Likely Configurable
Performance Variable Consistent
Reliability Best-effort SLA-backed
Custom methods Limited Full access

If you need archive data, trace methods, or high throughput, a dedicated node is often the right choice. OnFinality offers dedicated nodes for Polygon and many other networks.

Debugging common RPC issues

When your dApp cannot connect to Polygon, the issue is often one of the following:

  • Wrong chain ID: Ensure you are using 137 for mainnet and 80002 for Amoy.
  • Rate limiting: Public endpoints may return 429 or 403 errors. Consider upgrading to a paid plan.
  • Network congestion: If you see timeouts, try a different RPC provider or use a dedicated node.
  • WebSocket disconnects: Some providers limit WebSocket connections. Check your subscription logic and reconnect policy.

Here is a quick diagnostic script using curl to test connectivity:

curl -s https://polygon.api.onfinality.io/public \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}'
Enter fullscreen mode Exit fullscreen mode

If the response returns 0x89 (137), your connection is working.

Choosing the right RPC provider for Polygon

When evaluating RPC providers, compare the following criteria:

  • Uptime and reliability: Look for providers with a track record of high availability.
  • Throughput and rate limits: Understand the request-per-second limits and whether they fit your traffic.
  • Data availability: Do you need archive data or trace methods?
  • Geographic distribution: Global endpoints can reduce latency for users worldwide.
  • Pricing model: Flat-rate vs. usage-based pricing can affect your costs.

OnFinality provides a public Polygon endpoint and dedicated nodes with flexible pricing. See our RPC pricing for details.

Key Takeaways

  • Polygon mainnet uses chain ID 137 and the Amoy testnet uses 80002.
  • The official public RPC endpoint is https://polygon.api.onfinality.io/public.
  • Public endpoints are fine for development, but production apps should consider dedicated infrastructure.
  • Always verify chain ID and network name when configuring your wallet or dApp.

Frequently Asked Questions

What is the Polygon RPC endpoint?

The Polygon RPC endpoint is a URL that allows applications to interact with the Polygon blockchain via JSON-RPC. OnFinality provides a public endpoint at https://polygon.api.onfinality.io/public.

Is the Polygon RPC endpoint free?

Yes, the public endpoint is free to use, but it may have rate limits. For higher throughput, consider a paid plan or dedicated node.

How do I get a Polygon RPC endpoint?

You can use the public endpoint provided by OnFinality or sign up for a dedicated node. Visit our Polygon network page for more details.

What is the chain ID for Polygon?

The chain ID for Polygon mainnet is 137 (hex 0x89). The Amoy testnet uses 80002.

Can I use WebSocket for Polygon?

Yes, OnFinality provides a WebSocket endpoint at wss://polygon.api.onfinality.io/public for real-time updates.

Related resources

Originally published at OnFinality.

Top comments (0)