Docs

starknet_chainId - Get Starknet Chain ID

Returns the currently configured Starknet chain ID as a felt252 hex value. Used for network identification, transaction signing, and multi-chain routing.

Returns the currently configured Starknet chain ID as a hex-encoded felt252 value. This method is used to verify which Starknet network a node is connected to before signing transactions or deploying contracts.

Overview

Starknet chain IDs are encoded as felt252 values representing short ASCII strings. Unlike EVM chains that use numeric IDs, Starknet encodes human-readable network names into their felt representation. This is consistent with Starknet's use of felt252 as the fundamental data type in the Cairo language and the StarkNet OS.

Known Starknet Chain IDs

NetworkChain ID (ASCII)Chain ID (Hex felt252)
MainnetSN_MAIN0x534e5f4d41494e
Sepolia TestnetSN_SEPOLIA0x534e5f5345504f4c4941

The hex values are the ASCII byte representations of the network name strings.

Request Parameters

Request

This method accepts no parameters.

Response Body

Response
resultFELT

The chain ID as a hex-encoded felt252 value

Error Responses

Errors
Error 1
Error 2
Error 3

Examples

Bash
# Get the chain ID
curl -X POST https://api-starknet-mainnet.n.dwellir.com/YOUR_API_KEY \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "starknet_chainId",
    "params": [],
    "id": 1
  }'

# Decode the chain ID to ASCII
curl -s -X POST https://api-starknet-mainnet.n.dwellir.com/YOUR_API_KEY \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "starknet_chainId",
    "params": [],
    "id": 1
  }' | jq -r '.result' | python3 -c "import sys; h=sys.stdin.read().strip()[2:]; print(bytes.fromhex(h).decode())"

Use Cases

  • Network Verification - Confirm you are connected to mainnet or testnet before signing transactions with an Account contract
  • Multi-Network Applications - Route requests to the correct network handler based on chain ID
  • Transaction Signing - Include the correct chain ID in transaction signatures to prevent cross-network replays
  • Wallet Integrations - Display the connected Starknet network in wallet UIs
  • Deployment Pipelines - Gate contract deployments on the correct target network