Docs

state_getRuntimeVersion - XX Network RPC Method

Get the runtime version on XX Network. Essential for compatibility checking, upgrade detection, and transaction construction on a privacy-focused decentralized messaging and payment platform.

Returns the runtime version information for XX Network, including the spec name, spec version, implementation version, and supported API versions.

Why XX Network? Build on a privacy-focused decentralized messaging and payment platform with quantum-resistant cryptography and metadata privacy through cMix.

When to Use This Method

state_getRuntimeVersion is essential for XX Network developers building privacy-preserving applications:

  • Version Checking — Verify runtime compatibility before constructing transactions on XX Network
  • Upgrade Detection — Monitor for runtime upgrades that may change chain behavior for secure messaging, private payments, and quantum-resistant cryptography
  • Transaction Construction — Include the correct specVersion and transactionVersion in signed extrinsics
  • API Compatibility — Check which runtime APIs are available and at what version

Code Examples

Common Use Cases

1. Runtime Upgrade Monitor

Detect runtime upgrades on XX Network in real time:

JavaScript
async function monitorUpgrades(api) {
  let currentVersion = (await api.rpc.state.getRuntimeVersion()).specVersion.toNumber();
  console.log(`Starting monitor at spec version: ${currentVersion}`);

  const unsub = await api.rpc.chain.subscribeNewHeads(async (header) => {
    const version = await api.rpc.state.getRuntimeVersion(header.hash);
    const newVersion = version.specVersion.toNumber();

    if (newVersion !== currentVersion) {
      console.log(`Runtime upgrade detected! ${currentVersion} -> ${newVersion}`);
      currentVersion = newVersion;
      // Trigger reconnection or metadata refresh
    }
  });

  return unsub;
}

2. Transaction Construction with Correct Version

Include the correct version fields when constructing signed extrinsics:

JavaScript
async function getSigningPayloadInfo(api) {
  const version = await api.rpc.state.getRuntimeVersion();
  const genesisHash = await api.rpc.chain.getBlockHash(0);

  return {
    specVersion: version.specVersion.toNumber(),
    transactionVersion: version.transactionVersion.toNumber(),
    genesisHash: genesisHash.toHex(),
    // These fields are required for signing extrinsics
  };
}

3. Historical Version Comparison

Compare runtime versions across blocks to identify upgrade boundaries:

JavaScript
async function findUpgradeBlock(api, startBlock, endBlock) {
  const startHash = await api.rpc.chain.getBlockHash(startBlock);
  const startVersion = (await api.rpc.state.getRuntimeVersion(startHash)).specVersion.toNumber();

  // Binary search for upgrade block
  let low = startBlock;
  let high = endBlock;

  while (low < high) {
    const mid = Math.floor((low + high) / 2);
    const midHash = await api.rpc.chain.getBlockHash(mid);
    const midVersion = (await api.rpc.state.getRuntimeVersion(midHash)).specVersion.toNumber();

    if (midVersion === startVersion) {
      low = mid + 1;
    } else {
      high = mid;
    }
  }

  console.log(`Runtime upgraded at block #${low}`);
  return low;
}

Error Handling

Error CodeDescriptionSolution
-32603Internal errorNode may be syncing — retry with backoff
-32602Invalid paramsVerify block hash format is valid hex with 0x prefix
-32601Method not foundVerify the node supports this RPC method
-32005Rate limit exceededImplement client-side rate limiting