⚠️Blast API (blastapi.io) ends Oct 31. Migrate to Dwellir and skip the expensive compute units.
Switch Today →
Skip to main content

system_chain - JSON-RPC Method

Description

Returns the name of the chain the node is connected to. This JSON-RPC method is useful for identifying which Polkadot network (mainnet, testnet, or custom chain) the node is operating on.

Parameters

This method does not require any parameters.

Returns

FieldTypeDescription
resultstringThe name of the chain

Request Example

{
"jsonrpc": "2.0",
"method": "system_chain",
"params": [],
"id": 1
}

Response Example

{
"jsonrpc": "2.0",
"result": "Polkadot",
"id": 1
}

Code Examples

cURL

curl https://api-polkadot.n.dwellir.com \
-X POST \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "system_chain",
"params": [],
"id": 1
}'

JavaScript

const getChainName = async () => {
const response = await fetch('https://api-polkadot.n.dwellir.com', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
jsonrpc: '2.0',
method: 'system_chain',
params: [],
id: 1
})
});

const data = await response.json();
return data.result;
};

// Verify correct network
const chain = await getChainName();
console.log(`Connected to: ${chain}`);

if (chain !== 'Polkadot') {
console.warn('Warning: Not connected to Polkadot mainnet!');
}

Python

import requests
import json

def get_chain_name():
url = "https://api-polkadot.n.dwellir.com"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}

payload = {
"jsonrpc": "2.0",
"method": "system_chain",
"params": [],
"id": 1
}

response = requests.post(url, headers=headers, data=json.dumps(payload))
data = response.json()

if "error" in data:
raise Exception(f"RPC Error: {data['error']}")

return data["result"]

# Network detection
chain = get_chain_name()
print(f"Connected to: {chain}")

# Configure based on network
if chain == "Polkadot":
token_decimals = 10
token_symbol = "DOT"
elif chain == "Kusama":
token_decimals = 12
token_symbol = "KSM"
elif chain == "Westend":
token_decimals = 12
token_symbol = "WND"

Common Chain Names

Chain NameNetwork TypeDescription
PolkadotMainnetProduction network
KusamaCanaryExperimental network
WestendTestnetTest network
RococoTestnetParachain test network
Custom namesLocal/DevDevelopment chains

Use Cases

  1. Network Verification: Ensure connected to correct network
  2. Configuration Loading: Load network-specific settings
  3. Multi-chain Support: Handle different networks dynamically
  4. Error Prevention: Prevent mainnet transactions on testnet
  5. UI Adaptation: Display network-specific information

Network Detection Pattern

class NetworkManager {
constructor() {
this.networks = {
'Polkadot': {
symbol: 'DOT',
decimals: 10,
explorer: 'https://polkadot.subscan.io'
},
'Kusama': {
symbol: 'KSM',
decimals: 12,
explorer: 'https://kusama.subscan.io'
},
'Westend': {
symbol: 'WND',
decimals: 12,
explorer: 'https://westend.subscan.io'
}
};
}

async detectNetwork() {
const chain = await getChainName();
const config = this.networks[chain];

if (!config) {
throw new Error(`Unknown network: ${chain}`);
}

return { chain, ...config };
}

async validateNetwork(expectedChain) {
const chain = await getChainName();

if (chain !== expectedChain) {
throw new Error(
`Wrong network! Expected ${expectedChain}, got ${chain}`
);
}

return true;
}
}

Notes

  • Chain name is configured in the chain specification
  • Custom chains can have any name
  • Use in combination with system_properties for full network info
  • Chain name doesn't change during runtime
  • Case-sensitive string comparison