Polygon
准备好在生产环境中调用了吗?
免费套餐涵盖个人项目。按量付费,无需绑卡即可扩展。
Polygon
免费套餐涵盖个人项目。按量付费,无需绑卡即可扩展。
This page collects the Polygon operations developers reach for first: reading the latest block, checking MATIC and token balances, looking up transactions and receipts, fetching blocks, calling smart contracts, and pulling the gas price and nonce you need to send a transaction. Each example is a ready-to-run JSON-RPC 2.0 call against https://polygon.therpc.io/YOUR_API_KEY on chain ID 137 — the everyday building blocks for any app on Polygon PoS.
Two reads form the foundation of almost every Polygon integration. eth_blockNumber returns the height of the latest block Bor has produced — useful for confirmations and as a liveness check given Polygon's ~2-second cadence. eth_getBalance returns an account's native balance. Note that the value comes back in wei (the smallest unit) as a hex string; divide by 10^18 to convert it into human-readable MATIC.
Once a transaction is on Polygon, two reads tell you everything you need. eth_getTransactionByHash returns the transaction itself — sender, recipient, value, gas, and whether it has been mined into a block yet. eth_getTransactionReceipt returns the post-execution receipt: confirmation status, gas actually used, and the full log array, which is where you read the Transfer events and other emitted logs from QuickSwap, Aave, or any contract the transaction touched.
You can fetch any Polygon block two ways: eth_getBlockByNumber takes a block height (or a tag like latest), while eth_getBlockByHash takes the block's hash. Both accept a boolean second parameter that controls the payload: pass true to get every transaction expanded as a full object, or false to get back just the transaction hashes — the lighter option when you only need the block header and a list of which transactions it contains.
Reading from Polygon's smart contracts uses two methods. eth_call executes a contract's view or pure function without sending a transaction or spending gas — this is how you read an ERC-20 balanceOf, a Chainlink price, or a pool's reserves on QuickSwap. eth_getCode returns the deployed bytecode at an address, which lets you confirm a contract exists at that address and distinguish a contract from a plain wallet on chain ID 137.
Two quick checks confirm you are connected to the right network and that it is healthy. net_version returns the network ID as a string — 137 for Polygon PoS mainnet — so you can assert you are not accidentally talking to a testnet. eth_syncing reports the node's sync state, returning false when the node is fully caught up to the chain head and a progress object while it is still syncing.
Before sending a transaction on Polygon you typically read two values. eth_gasPrice returns the current gas price in wei — usually tiny on Polygon, where fees are a fraction of a cent, though it climbs during busy periods. eth_getTransactionCount returns an account's nonce, the running count of transactions it has sent. The nonce is required to sequence transactions correctly: each outgoing transaction from an address must use the next nonce in order, or it will be rejected or stuck.