net_version
https://api.triport.io/v1/ethereumReturns the current network ID as a decimal string (for example `"1"` for Ethereum mainnet).
net_version returns the network ID of the network the node is connected to,
encoded as a decimal string. For Ethereum mainnet this is "1".
Use this method for a quick connectivity check or to detect which network your
RPC connection is pointed at. Note that it is distinct from
eth_chainId: net_version returns the legacy network ID as
a decimal string, while eth_chainId returns the EIP-155 chain ID as a hex
quantity. The two values happen to coincide on mainnet but are not guaranteed to
match on every network. When you need the chain ID for replay-protected
transaction signing, prefer eth_chainId.
This method takes no parameters and is available on every tier.
Parameters
This method takes no parameters.
——optional[] as params.Response
Response fields
| Field | Type | Description |
|---|---|---|
result | string | The network ID as a decimal string. "1" is Ethereum mainnet. |
Errors
| Code | Meaning | When it happens |
|---|---|---|
-32001 | trial_expired | The API key's trial period has ended; upgrade to a paid tier to continue. |
-32003 | rate_limited | You exceeded the requests-per-second limit for your tier. Back off and retry. |
Errors are returned in the standard JSON-RPC envelope. See the shared errors reference for the full error object shape and handling guidance.
Examples
JavaScript (fetch)
const res = await fetch("https://api.triport.io/v1/ethereum", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.TRIPORT_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "net_version",
params: [],
}),
});
const { result } = await res.json();
console.log(result); // "1"
console.log(parseInt(result, 10)); // 1TypeScript SDK (@triport/sdk)
import { Triport } from "@triport/sdk";
const client = new Triport({ apiKey: process.env.TRIPORT_API_KEY! });
const networkId = await client.ethereum.rpc<string>("net_version", []);
console.log(networkId); // "1"
console.log(parseInt(networkId, 10)); // 1Python (triport-sdk)
import os
from triport import Triport
client = Triport(api_key=os.environ["TRIPORT_API_KEY"])
network_id = client.ethereum.rpc("net_version", [])
print(network_id) # "1"
print(int(network_id)) # 1Notes
- The result is a decimal string — parse it with
parseInt(result, 10)(JS) orint(result)(Python), not base 16. - The network ID is stable for the lifetime of a network, so the value is safe to cache for the duration of a session.
- Related: use
eth_chainIdfor the EIP-155 chain ID as a hex quantity (the value you need when signing transactions), andeth_blockNumberto read the current head once you have confirmed the network.