Summary
# Polygon Developer RPC Workflow: Connect, Test, and Prepare for Production
A Polygon developer usually needs three things first: the correct chain configuration, an RPC endpoint that supports the JSON-RPC methods used by the application, and a practical way to verify reads, transaction submission, and event handling. Polygon Mainnet uses chain ID 137, the native currency is POL, and the network is exposed through standard EVM JSON-RPC interfaces.
For a quick connection test, use the OnFinality Polygon RPC API endpoint https://polygon.api.onfinality.io/public. It can be used with tools such as curl, ethers, viem, Hardhat, and wallet configuration. For a production application, do not stop at a successful eth_chainId response: check the methods, request volume, historical-data needs, WebSocket requirements, monitoring approach, and failover plan that match your workload.
This page focuses on the practical RPC layer of Polygon development. Use the official Polygon developer documentation for Polygon protocol and application documentation, and use OnFinality's Polygon network page for current service details. You can also compare RPC pricing and review supported RPC networks before choosing an operating model.
Key Takeaways
- Polygon Mainnet uses chain ID 137, chain name Polygon Mainnet, and POL as its native currency.
- The OnFinality public Polygon RPC endpoint is https://polygon.api.onfinality.io/public.
- Validate an endpoint with eth_chainId, eth_blockNumber, and a small set of methods used by your application.
- Separate read traffic, transaction submission, logs, traces, and WebSocket subscriptions when evaluating infrastructure.
- Use confirmations and receipt polling rather than treating transaction submission as final settlement.
- Plan for provider errors, rate limits, reorganization-sensitive reads, and endpoint failover before launch.
- Consider a managed RPC API or dedicated node infrastructure when operational ownership becomes a bottleneck.
Chain settings at a glance
Use the network values below when configuring a wallet, client library, deployment tool, or application environment. The values correspond to Polygon Mainnet rather than Polygon Amoy testnet.
The endpoint shown is the official OnFinality public RPC URL provided for Polygon in the network configuration. Treat a public endpoint as a convenient connection option, not as a substitute for testing the specific request methods and traffic profile of your application.
- Network: Polygon Mainnet
- Chain ID: 137
- Native currency: POL
- Explorer: https://polygonscan.com
- HTTP RPC: https://polygon.api.onfinality.io/public
| Criterion | What to check | Why it matters |
|---|---|---|
| Network | Polygon Mainnet, not Polygon Amoy | A correct RPC URL with the wrong chain configuration can send reads or transactions to an unintended environment. |
| Chain ID | 137 | Wallets and signing libraries use the chain ID to identify the network and protect against replay across chains. |
| Native currency | POL with 18 decimals | Balance displays, fee calculations, and transaction value fields depend on the configured currency metadata. |
| Explorer | https://polygonscan.com | An explorer is useful for independently checking transaction hashes, addresses, and block references. |
The first five-minute RPC check
Start by checking the endpoint itself, then confirm that the response describes Polygon Mainnet. JSON-RPC responses contain either a result or an error object; both should be logged during integration testing.
The following request is deliberately small. It checks network identity and the current head without assuming that archive, trace, or log-query features are available.
- Confirm the HTTP status and JSON-RPC response shape.
- Decode the hexadecimal chain ID and verify that it equals 137.
- Record the block number and query it again after a short interval to confirm that the endpoint is advancing.
- Keep the request ID unique enough to correlate responses in logs.
- Do not expose API credentials in client-side code if your selected service requires authentication.
| Criterion | What to check | Why it matters |
|---|---|---|
| Identity | eth_chainId returns 0x89 | 0x89 is the hexadecimal representation of chain ID 137. |
| Head progress | eth_blockNumber returns a valid hexadecimal quantity | A changing head gives an initial indication that the endpoint is serving current chain data. |
| Application method | At least one read method used by your code | A basic identity response does not prove that every method, request size, or historical query is suitable for your workload. |
A reproducible JSON-RPC probe
Run this command from a development machine or CI job. It uses the OnFinality public Polygon endpoint and requests two standard methods in separate calls. In an automated check, parse the JSON rather than relying only on an HTTP 200 response.
- Compare the returned chain ID with the expected value before running deployment or migration scripts.
- Store block-number results as hexadecimal quantities or convert them carefully to an integer type.
- Add a timeout and retry policy at the client layer; avoid unbounded retries that can amplify an outage or rate-limit response.
- For transaction workflows, follow submission with receipt polling and application-level confirmation rules.
| Criterion | What to check | Why it matters |
|---|---|---|
| Request | curl -sS --max-time 10 -H 'content-type: application/json' --data '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}' https://polygon.api.onfinality.io/public | This verifies that the endpoint accepts a standard JSON-RPC request and identifies the connected chain. |
| Block query | Use eth_blockNumber with the same endpoint | This checks a second common read path without requiring an address, contract, or private key. |
| Failure handling | Inspect error.code, error.message, HTTP status, and timeout separately | Transport failures, provider policy errors, malformed requests, and application errors require different responses. |
Choose a client path that matches the application
Polygon is an EVM network, so common Ethereum-compatible development tools can be configured with the Polygon chain ID and an RPC URL. The choice of library is less important than keeping provider configuration, signing, and confirmation logic explicit.
A read-only service should not hold private keys. For deployments and transactions, sign locally or through a controlled signing system, then submit the signed transaction through the RPC provider. Keep nonce management and replacement-transaction behavior visible in your application design.
- Use viem or ethers for application reads, contract calls, gas estimation, and transaction submission.
- Use Hardhat or another deployment tool with Polygon Mainnet configured as a named network.
- Use a wallet connection only when the user must approve or sign an action; do not use wallet providers as your sole backend data source.
- Cache stable contract metadata, but avoid caching rapidly changing balances, nonces, or receipt state without a defined freshness policy.
- Validate contract addresses and ABI versions before interpreting returned data.
| Criterion | What to check | Why it matters |
|---|---|---|
| Frontend reads | Wallet provider versus backend RPC API | Wallet availability and user approval are not the same as dependable backend data access. |
| Backend reads | Explicit RPC URL, timeout, retry, and logging configuration | Backend services need predictable behavior when a request fails or traffic increases. |
| Writes | Local or controlled signing plus receipt tracking | Broadcasting a transaction does not by itself prove that the transaction was included or finalized according to your application rule. |
| Indexing | Logs, pagination, reorganization handling, and historical depth | A simple latest-state read is not enough for an indexer or analytics service. |
Production readiness checklist for Polygon apps
The right RPC setup depends on the workload. A small prototype may only need current-state reads and occasional transactions. A production indexer, trading interface, game backend, or analytics service can require sustained access to logs, historical blocks, subscriptions, or specialized methods.
Evaluate the service against observed application behavior rather than a generic request-per-second assumption. Measure response errors, timeouts, method-specific failures, and lag from the application's point of view. Do not infer service quality from a single successful request.
- Define separate budgets for reads, writes, logs, traces, and WebSocket connections.
- Check whether your application needs historical or archive-style state queries before launch.
- Confirm that event queries are paginated and bounded; very broad eth_getLogs ranges can be expensive or rejected.
- Use idempotent retry logic for reads and carefully designed retry rules for writes to avoid duplicate submissions.
- Monitor chain-head freshness, error rate, timeout rate, request duration, and receipt completion time.
- Keep a second connection strategy or documented recovery procedure for provider errors.
- Review the current OnFinality service and network pages for the service model that fits your requirements.
| Criterion | What to check | Why it matters |
|---|---|---|
| Prototype | Basic reads, contract calls, and manual transactions | A public RPC API can shorten setup while the application is still changing. |
| User-facing production app | Timeouts, retries, rate policies, logs, receipts, and failover | Interactive applications need predictable error handling during transient failures. |
| Indexer or analytics service | Historical access, eth_getLogs strategy, pagination, and reorganization handling | Data pipelines commonly make broader and more frequent queries than ordinary contract frontends. |
| Infrastructure buyer | Isolation, operational ownership, access control, and capacity planning | A dedicated node can be worth evaluating when shared access patterns do not match the workload. |
Failure modes developers should handle
RPC errors are not always Polygon protocol errors. A request can fail because of an invalid parameter, a provider policy, a timeout, a transport problem, or a temporary inability to serve the requested state. Record enough context to distinguish these cases.
For transaction flows, preserve the signed transaction hash and inspect its receipt. If a submission times out, do not immediately create a second transaction with the same business action unless your nonce and idempotency strategy accounts for the first submission possibly being accepted.
- Wrong chain: the wallet or client reports a chain ID other than 137. Check environment variables and network selection.
- Malformed quantity: JSON-RPC quantities must use the expected hexadecimal format and should not contain unnecessary leading zeroes.
- Event query rejected: reduce the block range, paginate requests, and verify that the contract address and topic filters are correct.
- Missing historical state: determine whether the selected RPC service and plan support the requested block or state query.
- WebSocket disconnect: reconnect with backoff, resubscribe, and reconcile missed blocks or events rather than assuming the stream was continuous.
- Receipt not found: continue controlled polling, check the transaction hash on an independent explorer, and apply an explicit timeout policy.
- Rate or access error: inspect response headers and provider documentation, then reduce concurrency or choose a service configuration suited to the workload.
| Criterion | What to check | Why it matters |
|---|---|---|
| Symptom | Chain ID mismatch | The application may be connected to Amoy, another EVM network, or an incorrectly configured endpoint. |
| Symptom | eth_getLogs error or timeout | Large ranges and high-volume contracts can create expensive queries; pagination makes the work more bounded. |
| Symptom | Duplicate business action | A client timeout does not prove that the original signed transaction was not accepted. |
| Symptom | Subscription gap | Reconnect logic must restore application state from a known block instead of trusting a potentially incomplete stream. |
Frequently Asked Questions
What is the Polygon Mainnet chain ID?
Polygon Mainnet uses chain ID 137, represented as 0x89 in a JSON-RPC eth_chainId response. Polygon Amoy is a separate testnet and should not be used in a Polygon Mainnet configuration.
What RPC endpoint can a Polygon developer use?
The OnFinality public Polygon RPC endpoint listed in the network configuration is https://polygon.api.onfinality.io/public. Check the current OnFinality Polygon page for service details and use a configuration appropriate for your workload.
Is Polygon RPC compatible with ethers and viem?
Polygon exposes standard EVM JSON-RPC methods, so libraries such as ethers and viem can be configured with the Polygon chain ID and an HTTP RPC URL. Verify method behavior, error handling, and transaction confirmation in your own integration.
Should I use Polygon Mainnet or Polygon Amoy while developing?
Use Polygon Amoy for testnet deployments and test-only transactions. Use Polygon Mainnet when interacting with production contracts and assets. Keep the two configurations separate to reduce the risk of sending a transaction to the wrong environment.
When should I consider a dedicated Polygon node?
Evaluate dedicated infrastructure when your workload needs greater operational isolation, predictable access patterns, specialized historical queries, or more control over node operations. Compare those requirements with a managed RPC API before deciding.
How should a Polygon developer monitor RPC health?
Monitor chain-head freshness, request errors, timeouts, response duration, method-specific failures, transaction receipt completion, and WebSocket reconnects where applicable. A useful probe checks both network identity and a representative application method.