# Polygon - Ethereum Layer 2

## Polygon RPC plans and rate limits

- **Free plan:** 20 responses per second, up to 100,000 responses a day.
- **Plans:** $49/mo, $299/mo, $999/mo with 25M, 150M, and 500M included responses. Overages billed at $5/$3/$2 per million responses respectively.
- **Paid rate limits:** 100 to 5,000 responses per second (bursts from 500 to 10,000), no daily limit.
- **Billing:** 1 response = 1 API credit on every shared plan, over HTTPS or WebSocket (WSS) where Polygon supports it.

Details: [Pricing](https://www.dwellir.com/docs/getting-started/pricing) · [Rate limits](https://www.dwellir.com/docs/getting-started/rate-limits) · [Authentication](https://www.dwellir.com/docs/getting-started/authentication) · [Archive nodes](https://www.dwellir.com/docs/getting-started/archive-nodes)

## Why Build on Polygon?

Polygon is a leading Ethereum scaling solution, providing a framework for building and connecting Ethereum-compatible blockchain networks. Built with Proof of Stake consensus, Polygon offers:

### **Lightning Fast Performance**

- **2 second block times** - Fast transaction confirmations
- **Up to 65,000 TPS** - Massive throughput capacity
- **$0.01 average transaction cost** - 10,000x cheaper than Ethereum

### **Enterprise Security**

- **100+ validators** - Highly decentralized network
- **$2B+ staked** - Strong economic security
- **Battle-tested since 2020** - Processing billions of transactions

### **Massive Ecosystem**

- **50M+ unique addresses** - One of the largest L2 user bases
- **7,000+ dApps** - Comprehensive DeFi, Gaming, and NFT ecosystem
- **Major integrations** - Aave, Uniswap, OpenSea, Chainlink

## Quick Start with Polygon

Connect to Polygon in seconds with Dwellir's optimized endpoints:

### Installation & Setup

ethers.js v6
web3.js
viem

```javascript
import { JsonRpcProvider } from 'ethers';

// Connect to Polygon via Dwellir
const provider = new JsonRpcProvider(
  'https://api-polygon-mainnet-full.n.dwellir.com/YOUR_API_KEY'
);

// Test connection
const blockNumber = await provider.getBlockNumber();
console.log('Connected to Polygon at block:', blockNumber);
```

```javascript
import Web3 from 'web3';

// Initialize Web3 with Dwellir endpoint
const web3 = new Web3(
  'https://api-polygon-mainnet-full.n.dwellir.com/YOUR_API_KEY'
);

// Verify connection
const chainId = await web3.eth.getChainId();
console.log('Connected to Polygon (Chain ID:', chainId, ')');
```

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

const client = createPublicClient({
  chain: polygon,
  transport: http('https://api-polygon-mainnet-full.n.dwellir.com/YOUR_API_KEY'),
});

const blockNumber = await client.getBlockNumber();
console.log('Current block:', blockNumber);
```

## Available Methods

### Core JSON-RPC Methods

Essential methods for interacting with the Polygon network:

| Method                      | Description                           | Link                                                 |
| --------------------------- | ------------------------------------- | ---------------------------------------------------- |
| `eth_blockNumber`           | Get the latest block number           | [View docs](https://www.dwellir.com/docs/polygon/eth_blockNumber)           |
| `eth_getBalance`            | Query MATIC/POL balance of an address | [View docs](https://www.dwellir.com/docs/polygon/eth_getBalance)            |
| `eth_getBlockByNumber`      | Retrieve block details by number      | [View docs](https://www.dwellir.com/docs/polygon/eth_getBlockByNumber)      |
| `eth_call`                  | Execute smart contract calls          | [View docs](https://www.dwellir.com/docs/polygon/eth_call)                  |
| `eth_getTransactionByHash`  | Get transaction details               | [View docs](https://www.dwellir.com/docs/polygon/eth_getTransactionByHash)  |
| `eth_getTransactionReceipt` | Fetch transaction receipts            | [View docs](https://www.dwellir.com/docs/polygon/eth_getTransactionReceipt) |
| `eth_sendRawTransaction`    | Broadcast signed transactions         | [View docs](https://www.dwellir.com/docs/polygon/eth_sendRawTransaction)    |
| `eth_estimateGas`           | Estimate gas for transactions         | [View docs](https://www.dwellir.com/docs/polygon/eth_estimateGas)           |
| `eth_gasPrice`              | Get current gas price                 | [View docs](https://www.dwellir.com/docs/polygon/eth_gasPrice)              |
| `eth_getLogs`               | Query event logs                      | [View docs](https://www.dwellir.com/docs/polygon/eth_getLogs)               |

### Debug & Trace Methods

Advanced methods for debugging and analyzing transactions:

| Method                     | Description                          | Link                                                |
| -------------------------- | ------------------------------------ | --------------------------------------------------- |
| `debug_traceTransaction`   | Detailed transaction execution trace | [View docs](https://www.dwellir.com/docs/polygon/debug_traceTransaction)   |
| `debug_traceBlock`         | Trace all transactions in a block    | [View docs](https://www.dwellir.com/docs/polygon/debug_traceBlock)         |
| `debug_traceBlockByNumber` | Trace block by number                | [View docs](https://www.dwellir.com/docs/polygon/debug_traceBlockByNumber) |

## Network Information

### Chain Details

| Parameter           | Mainnet                                          | Testnet (Amoy)                           |
| ------------------- | ------------------------------------------------ | ---------------------------------------- |
| **Chain ID**        | 137                                              | 80002                                    |
| **Currency**        | MATIC (transitioning to POL)                     | MATIC                                    |
| **Block Time**      | \~2 seconds                                      | \~2 seconds                              |
| **Block Gas Limit** | 30M                                              | 30M                                      |
| **RPC Endpoint**    | `https://api-polygon-mainnet-full.n.dwellir.com` | `https://api-polygon-amoy.n.dwellir.com` |

### Important Addresses

| Contract       | Address                                      |
| -------------- | -------------------------------------------- |
| **WMATIC**     | `0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270` |
| **USDC**       | `0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174` |
| **USDT**       | `0xc2132D05D31c914a87C6611C10748AEb04B58e8F` |
| **Multicall3** | `0xcA11bde05977b3631167028862bE2a173976CA11` |

## Best Practices

### 1. **Optimize Gas Usage**

Polygon has low fees, but optimizing gas usage is still important:

```javascript
// Use gas estimation for accurate pricing
const gasEstimate = await contract.estimateGas.transfer(to, amount);
const gasPrice = await provider.getGasPrice();
const txCost = gasEstimate * gasPrice;
```

### 2. **Handle Network Congestion**

Monitor and adapt to network conditions:

```javascript
// Implement dynamic gas pricing
const gasPrice = await provider.getGasPrice();
const adjustedGasPrice = gasPrice * 110n / 100n; // 10% buffer
```

### 3. **Leverage Polygon's Speed**

Take advantage of fast block times for better UX:

```javascript
// Quick confirmation monitoring
const tx = await wallet.sendTransaction(transaction);
const receipt = await tx.wait(1); // Usually confirms in 1 block (~2 seconds)
```

## Resources

- [Official Polygon Documentation](https://docs.polygon.technology/)
- [Polygon Network Explorer](https://polygonscan.com/)
- [Polygon Developer Portal](https://polygon.technology/developers)
- [Get Your Dwellir API Key](https://dashboard.dwellir.com)

## Support

Need help? Our team is available 24/7:

- **Email**: <support@dwellir.com>
- **Documentation**: You're already here!

Start building on Polygon with Dwellir's enterprise-grade infrastructure today.
