Logo
New RPC users get 35% off their first monthView the offer
RPC Assistant

Polygon Network RPC: Endpoints, Chain Settings, and Debugging

Summary

Learn how to connect to the Polygon network via RPC, including the official OnFinality public endpoint, chain settings, and common troubleshooting steps. This guide covers JSON-RPC methods, WebSocket support, and how to choose between public, shared, and dedicated RPC infrastructure for your dApp.

Quick decision guide: which Polygon RPC option fits your app?

Before diving into endpoints and methods, decide how you want to connect to Polygon. Your choice depends on traffic, reliability needs, and whether you need historical data.

  • Public RPC endpoint – Good for prototyping, hackathons, or low-traffic apps. The official OnFinality public endpoint is https://polygon.api.onfinality.io/public. It is free to use but shared, so it may have rate limits and is not ideal for production workloads.
  • Shared/Managed RPC – A managed service that provides a dedicated endpoint with higher throughput, WebSocket support, and often archive data. This is a common choice for production dApps that need consistent performance without running infrastructure.
  • Dedicated node – A full node provisioned exclusively for your project. This gives you the highest control, custom configuration, and no noisy neighbors. It is the best fit for high-traffic apps, indexers, or teams that need custom RPC methods.

If you are unsure, start with the public endpoint for testing, then move to a managed or dedicated solution as your user base grows. For a detailed comparison of providers, see our guide on choosing an RPC provider.

Polygon network at a glance

Polygon (formerly Matic Network) is a Layer 2 scaling solution for Ethereum. It uses a proof-of-stake (PoS) consensus and is EVM-compatible, meaning you can use the same tools and libraries as Ethereum. The mainnet is widely used for DeFi, gaming, and NFTs due to low fees and fast finality.

Here are the key chain settings you need to configure your wallet or dApp:

SettingValue
Network NamePolygon Mainnet
Chain ID137
Native CurrencyPOL (formerly MATIC)
SymbolPOL
Decimals18
Block Explorerhttps://polygonscan.com
Public RPC Endpointhttps://polygon.api.onfinality.io/public
WebSocket SupportYes (wss://polygon.api.onfinality.io/public)

Note: The native token was rebranded from MATIC to POL. Most RPC methods and wallets still reference the token as MATIC in some contexts, but the symbol is now POL.

How to connect to Polygon RPC

You can interact with Polygon RPC using standard Ethereum JSON-RPC methods. Here are examples using curl and popular libraries.

Using curl

To check the current block number:

curl -X POST https://polygon.api.onfinality.io/public \
  -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://polygon.api.onfinality.io/public");

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

getBlock();

Using viem

import { createPublicClient, http } from 'viem';
import { polygon } from 'viem/chains';

const client = createPublicClient({
  chain: polygon,
  transport: http('https://polygon.api.onfinality.io/public')
});

const blockNumber = await client.getBlockNumber();
console.log(blockNumber);

Wallet configuration

If you need to add Polygon to a wallet like MetaMask, use these 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

Common JSON-RPC methods on Polygon

Polygon supports most Ethereum JSON-RPC methods. Here are the ones you will use most often:

  • eth_blockNumber – Get the latest block number.
  • eth_getBalance – Get the balance of an address.
  • eth_call – Execute a read-only contract call.
  • eth_sendRawTransaction – Broadcast a signed transaction.
  • eth_getTransactionReceipt – Get the receipt of a transaction.
  • eth_getLogs – Fetch event logs (useful for indexing).
  • eth_estimateGas – Estimate gas for a transaction.

For a full list, refer to the Ethereum JSON-RPC specification. Polygon also supports the net_version and web3_clientVersion methods.

WebSocket support and real-time data

If your dApp needs real-time updates (e.g., price feeds, transaction status), use WebSocket. The OnFinality public endpoint supports WebSocket at wss://polygon.api.onfinality.io/public.

Example subscription to new block headers:

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));
});

Debugging common RPC issues

Even with a reliable endpoint, you may run into issues. Here are common problems and how to fix them.

1. Rate limiting

Public endpoints often have rate limits. If you see 429 Too Many Requests or rate limit exceeded, you need a higher-tier endpoint. Consider a managed RPC service or a dedicated node.

2. Transaction not found

If eth_getTransactionReceipt returns null, the transaction may be pending or dropped. Check the mempool with eth_getTransactionByHash. If it is not found, resubmit with a higher gas price.

3. Incorrect chain ID

Make sure your wallet or dApp uses chain ID 137. Using the wrong chain ID will cause transactions to fail.

4. WebSocket disconnections

WebSocket connections can drop. Implement reconnection logic with exponential backoff.

5. eth_getLogs timeouts

Querying logs over a large block range can time out. Use smaller ranges and paginate.

Public vs. managed vs. dedicated: what to consider

When choosing an RPC provider for Polygon, evaluate the following:

FactorPublicManagedDedicated
CostFreeSubscriptionHigher cost
Rate limitsYesHigher limitsCustom
ReliabilityBest effortHighHighest
Archive dataNoOptionalYes
WebSocketYesYesYes
Custom methodsNoLimitedYes

For production apps, a managed or dedicated solution is recommended. OnFinality offers dedicated nodes and managed RPC for Polygon, with support for archive data and WebSocket.

Polygon Amoy testnet

If you are developing on a testnet, Polygon Amoy is the recommended testnet (replacing the deprecated Mumbai). The chain ID is 80002 and the public RPC endpoint is https://polygon-amoy.api.onfinality.io/public. You can get test POL from the Amoy faucet.

Key Takeaways

  • Polygon mainnet uses chain ID 137 and the native token POL.
  • The official OnFinality public endpoint is https://polygon.api.onfinality.io/public.
  • Use WebSocket for real-time data.
  • For production, consider managed or dedicated RPC to avoid rate limits and ensure reliability.
  • Polygon Amoy is the testnet for development.

Frequently Asked Questions

What is the Polygon network RPC URL?

The public RPC URL for Polygon mainnet is https://polygon.api.onfinality.io/public. For the Amoy testnet, use https://polygon-amoy.api.onfinality.io/public.

What is the chain ID for Polygon?

The chain ID for Polygon mainnet is 137. The Amoy testnet uses 80002.

Is Polygon RPC compatible with Ethereum?

Yes, Polygon is EVM-compatible, so you can use Ethereum JSON-RPC methods and libraries like ethers.js and viem.

How do I get test POL for Polygon Amoy?

You can get test POL from the Amoy faucet. Check the Polygon network page for more details.

Why am I getting rate limited on the public endpoint?

Public endpoints are shared and have rate limits. For higher limits, consider a managed RPC service or a dedicated node.

For a full list of supported networks, visit our networks page.

RPC Knowledge Base

Related RPC details

Never Worry about Infrastructure Again

OnFinality takes away the heavy lifting of DevOps so you can build smarter and faster.

Get Started