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 Hydration 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": "Hydration",
"id": 1
}
Code Examples
cURL
curl https://api-hydration.n.dwellir.com/YOUR_API_KEY \
-X POST \
-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-hydration.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
})
});
const data = await response.json();
return data.result;
};
// Verify correct network
const chain = await getChainName();
console.log(`Connected to: ${chain}`);
if (chain !== 'Hydration') {
console.warn('Warning: Not connected to Hydration mainnet!');
}
Python
import requests
import json
def get_chain_name():
url = "https://api-hydration.n.dwellir.com/YOUR_API_KEY"
headers = {
"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 == "Hydration":
token_decimals = 12
token_symbol = "HDX"
elif chain == "Basilisk":
token_decimals = 12
token_symbol = "BSX"
else:
token_decimals = 12
token_symbol = "UNIT"
Common Chain Names
Chain Name | Network Type | Description |
---|---|---|
Hydration | Mainnet | Production liquidity parachain secured by Polkadot |
Basilisk | Testnet (Kusama) | Staging network that mirrors Hydration runtime for pre-production |
Local Testnet | Dev | Custom chain specification for local testing |
Custom names | Local/Dev | Alternate configurations or forks |
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 = {
'Hydration': {
symbol: 'HDX',
decimals: 12,
explorer: 'https://hydration.subscan.io'
},
'Basilisk': {
symbol: 'BSX',
decimals: 12,
explorer: 'https://basilisk.subscan.io'
},
'Local Testnet': {
symbol: 'HDX',
decimals: 12,
explorer: 'https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944#/explorer'
}
};
}
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
Related Methods
state_getRuntimeVersion
- Get runtime versionsystem_health
- Get node healthrpc_methods
- List available methodsstate_getMetadata
- Get runtime metadata