⚠️Blast API (blastapi.io) ends Oct 31. Migrate to Dwellir and skip Alchemy's 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 Moonbase Alpha 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": "Moonbase Alpha",
"id": 1
}

Code Examples

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

Common Chain Names

Chain NameNetwork TypeDescription
Moonbase AlphaTestnetMoonbeam public 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 = {
'Moonbase Alpha': {
symbol: 'DEV',
decimals: 18,
explorer: 'https://moonbase.moonscan.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