Logo
RPC Assistant

Polygon RPC: The Developer's Guide to Endpoints, Providers, and Best Practices

摘要

This guide covers everything you need to know about Polygon RPC endpoints: what they are, how to find reliable public and private endpoints, and how to choose the right provider for your dApp. Whether you're building on Polygon PoS mainnet or testing on Amoy, you'll get practical advice on performance, rate limits, and troubleshooting common issues.

Polygon RPC decision checklist

Before you integrate a Polygon RPC endpoint, evaluate these factors to avoid common pitfalls:

CriterionWhat to checkWhy it matters
Network & Chain IDConfirm you are using Polygon PoS mainnet (Chain ID 137) or Amoy testnet (Chain ID 80002)Wrong chain ID can cause transaction failures or fund loss
Rate limitsPublic endpoints often cap requests per second (e.g., 10-100 req/s)Exceeding limits leads to 429 errors and dropped requests
Uptime & reliabilityCheck historical uptime and node redundancyDowntime can break your dApp or cause missed blocks
Data freshnessEnsure the endpoint returns the latest block quicklyStale data can lead to incorrect state reads
WebSocket supportVerify WSS endpoint availability for real-time subscriptionsRequired for event listeners and live updates
Privacy & securityPublic endpoints may log your IP and requestsSensitive applications need private endpoints
Archive dataDo you need historical state? Archive nodes store full historyRequired for certain queries like eth_getLogs over large ranges
CostCompare free vs paid tiers, and understand pricing modelsUnplanned costs can blow your budget

What is a Polygon RPC endpoint?

A Polygon RPC (Remote Procedure Call) endpoint is a URL that allows your application to communicate with the Polygon blockchain. It acts as a gateway, enabling you to send transactions, query balances, call smart contracts, and subscribe to events using standard JSON-RPC methods like eth_call, eth_getBalance, and eth_sendRawTransaction.

Polygon is an Ethereum-compatible (EVM) sidechain, so its RPC interface is nearly identical to Ethereum's. This means you can use the same Web3 libraries (ethers.js, web3.js, viem) and tools (Hardhat, Foundry, Remix) with minimal configuration changes.

Polygon network details

Polygon PoS Mainnet

  • Chain ID: 137 (0x89)
  • Currency: POL (formerly MATIC)
  • RPC endpoint: https://polygon.api.onfinality.io/public
  • WSS endpoint: wss://polygon.api.onfinality.io/public
  • Block explorer: PolygonScan

Polygon Amoy Testnet

  • Chain ID: 80002
  • Currency: POL (testnet)
  • RPC endpoint: https://polygon-amoy.api.onfinality.io/public
  • WSS endpoint: wss://polygon-amoy.api.onfinality.io/public
  • Block explorer: Amoy Polygonscan
  • Faucet: Available via the official Polygon faucet

How to use a Polygon RPC endpoint

1. Add to MetaMask

  1. Open MetaMask and click the network dropdown.
  2. Click "Add Network" and then "Add a network manually".
  3. Fill in the details:
    • Network Name: Polygon Mainnet
    • RPC URL: https://polygon.api.onfinality.io/public
    • Chain ID: 137
    • Currency Symbol: POL
    • Block Explorer URL: https://polygonscan.com
  4. Click "Save".

2. Use with ethers.js

import { ethers } from "ethers";

const provider = new ethers.JsonRpcProvider("https://polygon.api.onfinality.io/public");
const blockNumber = await provider.getBlockNumber();
console.log("Current block:", blockNumber);

3. Use with curl

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

Public vs private Polygon RPC endpoints

Public endpoints

Public RPC endpoints are free and easy to use. They are great for prototyping, small projects, and personal use. However, they come with limitations:

  • Rate limits: Typically 10-100 requests per second. Exceeding these limits results in HTTP 429 errors.
  • No reliability expectations: Public nodes can go offline without notice.
  • No privacy: Your IP address and request data are visible to the node operator.
  • Limited data: Some public endpoints do not support archive data or debug/trace methods.

Popular public Polygon RPC endpoints include:

  • https://polygon.api.onfinality.io/public
  • https://polygon-bor-rpc.publicnode.com
  • https://polygon.drpc.org
  • https://1rpc.io/matic

Private endpoints

Private (or dedicated) endpoints are provisioned for your exclusive use. They offer:

  • Higher rate limits: Customizable to your needs, often thousands of requests per second.
  • Better reliability: Redundant infrastructure with SLAs.
  • Enhanced privacy: Your requests are not shared with other users.
  • Full API access: Support for archive data, debug/trace methods, and custom configurations.

Providers like OnFinality offer dedicated Polygon nodes that can be tailored to your application's requirements. You can choose between shared and dedicated infrastructure depending on your scale and budget.

Common issues and troubleshooting

429 Too Many Requests

This error indicates you have exceeded the rate limit of the endpoint. Solutions:

  • Reduce request frequency: Implement exponential backoff or batch requests.
  • Upgrade to a private endpoint: Private endpoints offer higher or clear rate limits.
  • Use multiple endpoints: Distribute requests across several public endpoints (but be aware of data consistency).

Connection timeouts

Timeouts can occur due to network congestion or node overload. Try:

  • Switching to a different endpoint from the list above.
  • Using a WebSocket endpoint for real-time subscriptions (more efficient for event-driven apps).
  • Contacting your provider if the issue persists.

Stale data

If you receive outdated block data, the node may be lagging. Verify the latest block number using a block explorer. For production, use endpoints with proven low latency.

How to choose a Polygon RPC provider

When selecting a provider for your Polygon dApp, consider the following:

  1. Performance: Look for low latency and high throughput. Test endpoints with tools like curl or wscat.
  2. Reliability: Check uptime history and whether the provider offers redundant nodes.
  3. Scalability: Ensure the provider can handle your peak request volume without degradation.
  4. Support: Evaluate the quality of documentation and technical support.
  5. Pricing: Compare free tiers, pay-as-you-go, and dedicated plans. See RPC pricing for details.
  6. Network coverage: Does the provider support both mainnet and testnet? OnFinality supports Polygon mainnet and Amoy testnet.

Key Takeaways

  • Polygon RPC endpoints allow your dApp to interact with the Polygon blockchain using standard JSON-RPC.
  • Public endpoints are free but come with rate limits and no guarantees; private endpoints offer better performance and reliability.
  • Always verify the network (mainnet vs testnet) and chain ID to avoid costly mistakes.
  • For production applications, consider using a dedicated node or a premium RPC service to ensure uptime and scalability.
  • Test your endpoint thoroughly before deploying to production.

Frequently Asked Questions

Q: What is the difference between Polygon RPC and Ethereum RPC?

A: Polygon is EVM-compatible, so the RPC interface is nearly identical. The main differences are the chain ID (137 vs 1) and the underlying consensus mechanism (Polygon uses a modified Proof-of-Stake with Bor and Heimdall layers).

Q: Can I use a free Polygon RPC for production?

A: It depends on your traffic. Free public endpoints are suitable for low-volume applications and testing. For production with high traffic, a private endpoint is recommended to avoid rate limits and downtime.

Q: How do I get a Polygon RPC URL?

A: You can use public endpoints listed in this guide, or sign up with a provider like OnFinality to get a dedicated endpoint. See supported RPC networks for more options.

Q: What is the Polygon Amoy testnet RPC?

A: The Amoy testnet RPC endpoint is https://polygon-amoy.api.onfinality.io/public with Chain ID 80002. It is used for testing before deploying to mainnet.

Q: How do I check my Polygon RPC endpoint is working?

A: Use curl to send a simple eth_blockNumber request. If you get a valid JSON response with a block number, the endpoint is working.

Q: What are the rate limits for public Polygon RPC?

A: Rate limits vary by provider. Typically, public endpoints allow 10-100 requests per second. Check the provider's documentation for exact limits.

Q: Can I use WebSocket with Polygon RPC?

A: Yes, many providers offer WebSocket endpoints (e.g., wss://polygon.api.onfinality.io/public). WebSocket is recommended for real-time subscriptions.

Q: What is the best Polygon RPC provider?

A: The best provider depends on your needs. For a balance of performance, reliability, and pricing, consider OnFinality. Evaluate multiple providers using the checklist above.

Q: How do I add Polygon to MetaMask?

A: Use the network details provided in this guide (Chain ID 137, RPC URL, etc.) and add it manually in MetaMask's network settings.

Q: What is the difference between Polygon PoS and Polygon zkEVM?

A: Polygon PoS is a sidechain with its own validator set, while Polygon zkEVM is a zero-knowledge rollup that inherits security from Ethereum. They have different RPC endpoints and chain IDs.

RPC 知识库

相关 RPC 内容

Rpc Provider Selection

如何为生产级 dApp 选择 TON RPC 提供商?

# 如何为生产级 dApp 选择 TON RPC 提供商? 开放网络(TON)是一个为大规模采用而设计的分片 Layer 1 区块链,为 Telegram Mini Apps、DeFi 协议和支付系统提供支持。选择合适的 TON RPC 提供商对于确保低延迟、高可靠性以及访问 ADNL 和归档数据等...

Network Rpc

什么是Pichiu网络以及如何通过RPC连接?

# 什么是Pichiu网络以及如何通过RPC连接? Pichiu网络是一个专注于去中心化预言机服务的区块链项目,使智能合约能够安全地与链下数据交互。它基于Substrate构建,为数据馈送和跨链通信提供了强大的基础设施。对于在Pichiu上构建的开发者来说,可靠的RPC端点对于查询链上数据和提交交易...

Testnet Rpc

BNB测试网RPC:端点、设置与最佳提供商完全指南

# BNB测试网RPC:端点、设置与最佳提供商完全指南 BNB智能链测试网(链ID 97)是一个公开的EVM兼容测试网络,镜像了BNB智能链主网的功能。它使用无价值的tBNB作为燃料费,使开发者能够在无需承担真实资金风险的情况下部署和测试智能合约、dApp及集成。本指南涵盖您需要了解的关于BNB测试...

Rpc Provider Selection

哪个RPC提供商提供最可靠的以太坊RPC端点?

# 哪个RPC提供商提供最可靠的以太坊RPC端点? 以太坊RPC端点的可靠性意味着持续的正常运行时间、低延迟、准确的数据以及处理流量高峰而不受速率限制或错误的能力。没有哪个提供商能普遍适用于所有工作负载,但生产团队应根据端点性能、方法支持、归档和追踪访问以及扩展选项来评估提供商。OnFinality...

Rpc Provider Selection

Web3项目的最佳RPC提供商是什么?

Web3项目的最佳RPC提供商是能够支持您所需网络、保持延迟和正常运行时间可预测、提供清晰的请求可见性,并在流量增长时允许您从共享RPC端点扩展到专用节点基础设施的提供商。 对于许多生产团队来说,这意味着比较支持的链、请求限制、归档和Trace API支持、定价、分析、区域性能以及支持响应质量。On...

Network Rpc

关于RPC端点,我需要了解什么?

# 关于RPC端点,我需要了解什么? RPC端点至关重要,因为Web3应用程序依赖于稳定的端点访问来进行读取、交易、仪表盘和后端工作流。正确的设置应匹配您的工作负载,支持您所需的网络和测试网,使限制可见,并在共享RPC不再足够时为您提供扩展路径。 对于通用Web3构建者、基础设施负责人、DeFi团队...

永远不用担心基础设施

OnFinality 消除了 DevOps 的繁重工作,让您能够更聪明、更快地构建。

开始