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

Polygon Mainnet RPC: How Do You Connect to Chain ID 137?

Summary

Polygon Mainnet is an EVM-compatible chain identified by chain ID 137, with POL as its native gas token. To connect, point your wallet or app at an HTTP or WebSocket RPC endpoint and confirm the chain ID matches 137 before sending transactions. OnFinality provides a public Polygon endpoint for testing and dedicated Polygon node infrastructure for production workloads that need consistent capacity.

Polygon Mainnet is an EVM-compatible network with chain ID 137 and POL as its native gas token. If you are wiring a wallet, a backend indexer, or a trading bot to Polygon, the first thing you need is a working RPC endpoint plus the correct chain settings. This page gives you the settings, a few request examples, and a practical way to decide between a public endpoint and dedicated node infrastructure.

Quick recommendation: public endpoint or dedicated node?

Start with the public endpoint when you are prototyping, running a script, or verifying that your wallet config is correct. It is the fastest way to confirm chain ID, balances, and contract calls without any signup.

Move to a dedicated Polygon node when any of these apply:

  • You send a steady stream of eth_call, eth_getLogs, or eth_sendRawTransaction requests and cannot tolerate shared capacity.
  • You need predictable throughput during mints, liquidations, or other burst events.
  • You rely on WebSocket subscriptions such as newHeads or logs and want a connection you control.
  • You need archive-style historical reads or trace-style debugging that public endpoints often restrict.

OnFinality offers both: a public Polygon endpoint for development and dedicated node infrastructure for production. You can review RPC pricing and supported RPC networks to see what fits your workload.

Polygon Mainnet chain settings at a glance

Use these values when adding Polygon to a wallet, a Hardhat config, or a backend client.

SettingValue
Network namePolygon Mainnet
Chain ID137
Native currencyPOL (18 decimals)
Block explorerhttps://polygonscan.com
TransportHTTP and WebSocket
Public RPC URLhttps://polygon.api.onfinality.io/public

If a tool asks for a "network ID" separately from a chain ID, use 137 for both on Polygon Mainnet. Mismatched IDs are one of the most common causes of "wrong network" errors in wallets and dApps.

Connecting from a wallet

Most EVM wallets accept a custom network. Enter the values above, then confirm that the wallet shows POL as the gas token and that your address balance loads. If the balance is empty but you expect funds, check that you are not still pointed at a testnet such as Polygon Amoy (chain ID 80002).

A common mistake is pasting a testnet RPC URL while keeping the mainnet chain ID, or the reverse. The wallet will either refuse to connect or silently show the wrong balances. Always pair the endpoint with chain ID 137 for mainnet.

Making your first JSON-RPC calls

You can verify an endpoint with a single curl request. The example below asks for the current block number:

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

A healthy response returns a hex block number. From there, you can check chain ID and fetch a balance:

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

The eth_chainId result should be 0x89, which is 137 in decimal. If you get a different value, you are talking to the wrong network.

Using Polygon from JavaScript

With ethers, you can point a provider at the endpoint and read state without managing keys:

import { JsonRpcProvider, formatEther } from "ethers";

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

const network = await provider.getNetwork();
console.log("chainId:", network.chainId.toString()); // 137

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

const balance = await provider.getBalance("0xYourAddressHere");
console.log("POL balance:", formatEther(balance));

If you use viem, the same idea applies with createPublicClient and http() pointing at the endpoint. For sending transactions, add a signer and make sure the account holds enough POL to cover gas.

WebSocket subscriptions on Polygon

Polygon supports WebSocket transport, which is useful for reacting to new blocks or specific contract events without polling. A minimal subscription looks like this:

import WebSocket from "ws";

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

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

ws.on("message", (data) => {
  const msg = JSON.parse(data.toString());
  if (msg.method === "eth_subscription") {
    console.log("new head:", msg.params.result.number);
  }
});

WebSocket connections are stateful, so plan for reconnects. If your app depends on long-lived subscriptions, a dedicated node gives you a connection that is not shared with unrelated traffic.

What breaks first in production

Most Polygon RPC problems are not exotic. They fall into a few repeatable categories:

SymptomLikely causeWhat to check
"Wrong network" in walletChain ID does not match endpointConfirm chain ID 137 and mainnet URL
Empty balancePointed at testnetCheck for Amoy (80002) vs mainnet (137)
Requests slow or throttledShared public capacityMove heavy reads to a dedicated node
eth_getLogs fails or times outWide block range on shared endpointNarrow the range or use a node sized for log queries
Subscription dropsIdle or unstable WebSocketAdd reconnect logic and heartbeat
Transaction stuckGas price too low for current conditionsRe-estimate gas and check POL balance

If you are debugging a specific failure, isolate it: run eth_chainId, then eth_blockNumber, then the failing method. That sequence tells you whether the problem is the endpoint, the network, or your request payload.

Choosing infrastructure for Polygon workloads

The right choice depends on what your app actually does. A quick way to frame it:

WorkloadPublic endpointDedicated node
Prototyping and scriptsGood fitNot needed
Wallet or dApp readsUsually fineUseful at scale
High-volume indexingRiskyRecommended
WebSocket subscriptionsLimitedRecommended
Archive or trace queriesOften restrictedRecommended
Burst traffic (mints, liquidations)UnpredictableRecommended

OnFinality's Polygon RPC network page lists the endpoint and transport details. If you are comparing providers more broadly, the RPC provider selection guide covers criteria such as method support, failover, and observability.

Adding failover and monitoring

A single endpoint is a single point of failure. For production, run at least two endpoints and switch on error or latency thresholds. A simple health probe can check chain ID and block freshness:

async function probe(url) {
  const res = await fetch(url, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      jsonrpc: "2.0",
      id: 1,
      method: "eth_chainId",
      params: []
    })
  });
  const data = await res.json();
  return data.result === "0x89";
}

Run this on a schedule and route traffic away from endpoints that fail or lag. Track block height over time so you can spot a node that is falling behind rather than failing outright.

Key Takeaways

  • Polygon Mainnet uses chain ID 137 and POL as its native gas token.
  • The public OnFinality endpoint at https://polygon.api.onfinality.io/public is suitable for development and verification.
  • Confirm eth_chainId returns 0x89 before trusting any endpoint.
  • Use WebSocket transport for subscriptions, and add reconnect logic.
  • Move heavy reads, log queries, and subscriptions to a dedicated node when shared capacity becomes a bottleneck.
  • Always plan for failover and monitor block freshness, not just uptime.

Frequently Asked Questions

What is the Polygon Mainnet RPC URL?

OnFinality's public Polygon endpoint is https://polygon.api.onfinality.io/public. For production, use a dedicated endpoint from your provider dashboard.

What is Polygon's chain ID?

Polygon Mainnet uses chain ID 137, which is 0x89 in hex. Polygon Amoy, the testnet, uses chain ID 80002.

Does Polygon RPC support WebSocket?

Yes. Polygon supports HTTP and WebSocket transport. Use WebSocket for eth_subscribe methods such as newHeads and logs.

Can I use the public endpoint in production?

You can, but shared capacity is unpredictable under load. For steady traffic, bursts, or subscriptions, a dedicated node is the safer choice.

How do I know if my endpoint is on the wrong network?

Call eth_chainId. If it does not return 0x89, you are connected to a different network or a testnet.

Where can I see supported Polygon endpoints and pricing?

See the Polygon network page, RPC pricing, and the full list of supported RPC networks.

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