eth_chainId
https://api.triport.io/v1/polygonReturns the Polygon network's EIP-155 chain ID as a hex string — `0x89` (137) on mainnet.
eth_chainId returns the chain ID of the connected network as a hex-encoded
integer. On Polygon mainnet this is the constant 0x89 (137 decimal). It is the
cheapest possible call against the Polygon RPC surface — one request resolves to
a single immutable constant — which makes it a common liveness ping.
Its primary purpose is EIP-155 replay protection: the chain ID is mixed into the transaction signature so that a transaction signed for Polygon cannot be replayed on another EVM chain. Wallets and signing libraries call it once before constructing a transaction. Because the value never changes for a given network, clients should fetch it once per connection and cache it indefinitely (TTL = ∞).
This method belongs to the free polygon_read_rpc category, so it is available
on every tier starting at Free. It takes no parameters. If you are targeting
the Polygon Amoy testnet instead of mainnet, the returned value is 0x13882
(80002 decimal).
Note:
net_versionreturns the same chain identity as a decimal string ("137") rather than a hex quantity. Prefereth_chainIdfor EIP-155 and modern signing flows;net_versionexists mainly for legacy Web3.js (< 4.x) chain detection.
Parameters
This method takes no parameters. Pass an empty params array.
——optionalResponse
Response fields
| Field | Type | Description |
|---|---|---|
jsonrpc | string | JSON-RPC version, always "2.0". |
id | number | string | Echoes the request id. |
result | string | Chain ID as a hex quantity. 0x89 (137) on Polygon mainnet; 0x13882 (80002) on Amoy testnet. |
Errors
Errors follow the standard JSON-RPC error envelope. See the shared
errors reference for the full error.data shape
(current_tier, required_tier, limit_rps, retry_after_sec, upgrade_url,
…).
| Code | Meaning | When it happens |
|---|---|---|
-32001 | trial_expired | The trial period for the API key has ended; upgrade to a paid tier. |
-32002 | tier_insufficient | Your tier is below the method's required tier. (Not applicable here — eth_chainId is Free — but returned by premium namespaces such as bor_*/trace_*.) |
-32003 | rate_limited | You exceeded your tier's RPS limit (15 rps on Free). Honor retry_after_sec and retry with backoff. |
-32004 | subscription_expired | The subscription tied to the API key is no longer active. |
-32005 | unauthorized | Missing or invalid Authorization header, or the key lacks the polygon_read_rpc category. |
-32601 | method_unknown | The method name is not recognized for this chain/route. |
Examples
JavaScript (fetch)
const res = await fetch("https://api.triport.io/v1/polygon", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.TRIPORT_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "eth_chainId",
params: [],
}),
});
const { result } = await res.json();
const chainId = parseInt(result, 16); // 137
console.log(`Connected to Polygon chain ${chainId}`);TypeScript SDK (@triport/sdk)
import { TriportClient } from "@triport/sdk";
const client = new TriportClient({
apiKey: process.env.TRIPORT_API_KEY!,
network: "polygon",
});
const chainId = await client.rpc<string>("eth_chainId");
console.log(parseInt(chainId, 16)); // 137Python (triport-sdk)
import os
from triport import TriportClient
client = TriportClient(
api_key=os.environ["TRIPORT_API_KEY"],
network="polygon",
)
chain_id_hex = client.rpc("eth_chainId") # "0x89"
print(int(chain_id_hex, 16)) # 137Notes
- Cache aggressively. The chain ID is immutable per network — fetch it once per connection and reuse it. There is no need to re-poll.
- Mainnet vs testnet.
0x89= Polygon mainnet (137);0x13882= Polygon Amoy testnet (80002). Always confirm you are signing for the chain you intend. - EIP-155. Pass the decoded integer (
137) as thechainIdfield when constructing and signing transactions to enable cross-chain replay protection. - Related methods:
net_version(same identity, decimal string),eth_blockNumber(chain liveness/tip),web3_clientVersion(node client string).