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#
| Field | Type | Description |
|---|---|---|
result | string | The 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
- Python
- JavaScript
curl https://api-polkadot.n.dwellir.com/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "system_chain",
"params": [],
"id": 1
}'
import requests, json
payload = {"jsonrpc":"2.0","method":"system_chain","params":[],"id":1}
r = requests.post("https://api-polkadot.n.dwellir.com/YOUR_API_KEY",
headers={"Content-Type":"application/json"},
data=json.dumps(payload))
print(r.json()["result"])
const res = await fetch('https://api-polkadot.n.dwellir.com/YOUR_API_KEY', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ jsonrpc: '2.0', method: 'system_chain', params: [], id: 1 })
});
console.log((await res.json()).result);
Common Chain Names#
| Chain Name | Network Type | Description |
|---|---|---|
Polkadot | Mainnet | Production network |
Kusama | Canary | Experimental network |
Westend | Testnet | Test network |
Rococo | Testnet | Parachain test network |
| Custom names | Local/Dev | Development chains |
Use Cases#
- Network Verification: Ensure connected to correct network
- Configuration Loading: Load network-specific settings
- Multi-chain Support: Handle different networks dynamically
- Error Prevention: Prevent mainnet transactions on testnet
- 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_propertiesfor full network info - Chain name doesn't change during runtime
- Case-sensitive string comparison
Related Methods#
state_getRuntimeVersion- Get runtime versionsystem_health- Get node healthrpc_methods- List available methodsstate_getMetadata- Get runtime metadata