# state_getRuntimeVersion - FLOP RPC Method

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

> **Why FLOP?** Build on the Substrate Proof of Inference Layer 1 built for autonomous AI agents with Proof of Inference with TOPLOC activation commitments, full historical archive state from genesis, and JSON-RPC v2 archive and chainHead APIs.

## When to Use This Method

`state_getRuntimeVersion` is essential for AI agent builders, FLOP miners, indexers, and Substrate developers:

- **Version Checking** - Verify runtime compatibility before constructing transactions on FLOP
- **Upgrade Detection** - Monitor for runtime upgrades that may change chain behavior for Proof of Inference settlement, 1-second BABE blocks with AlephBFT finality, archive state queries, and HTLC atomic swaps
- **Transaction Construction** - Include the correct `specVersion` and `transactionVersion` in signed extrinsics
- **API Compatibility** - Check which runtime APIs are available and at what version

## Best Practices

- Track `specVersion` changes to detect runtime upgrades and potential forks
- The `authoringVersion` tracks block authoring protocol compatibility
- Use with `system_health` to verify node is synced before checking version
- Cache version information -- it only changes on runtime upgrades

## Request Parameters

- `blockHash` (`String, optional`): Block hash to query version at. If omitted, returns the current runtime version

## Request Example

```json
{
  "jsonrpc": "2.0",
  "method": "state_getRuntimeVersion",
  "params": [],
  "id": 1
}
```

## Response Fields

- `specName` (`String, required`): Runtime specification name (e.g., polkadot, kusama)
- `implName` (`String, required`): Implementation name (e.g., parity-polkadot)
- `authoringVersion` (`Number, required`): Authoring version for block creation
- `specVersion` (`Number, required`): Specification version - incremented on breaking changes
- `implVersion` (`Number, required`): Implementation version - incremented on non-breaking changes
- `transactionVersion` (`Number, required`): Transaction format version - must match when signing
- `stateVersion` (`Number, required`): State trie version
- `apis` (`Array, required`): List of supported runtime API IDs and versions

## Successful Response

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "specName": "polkadot",
    "implName": "parity-polkadot",
    "authoringVersion": 0,
    "specVersion": 1003000,
    "implVersion": 0,
    "transactionVersion": 26,
    "stateVersion": 1,
    "apis": [
      ["0xdf6acb689907609b", 5],
      ["0x37e397fc7c91f5e4", 2],
      ["0x40fe3ad401f8959a", 6]
    ]
  }
}
```

## Error Responses

### Error Response

- Code: `-32603`

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32603,
    "message": "Internal error"
  }
}
```

## Code Examples

cURL
JavaScript
Python
Rust

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

```javascript
import { ApiPromise, WsProvider } from '@polkadot/api';

const provider = new WsProvider('wss://api-flop-testnet.n.dwellir.com/YOUR_API_KEY');
const api = await ApiPromise.create({ provider });

// Get current runtime version
const version = await api.rpc.state.getRuntimeVersion();
console.log('Spec name:', version.specName.toString());
console.log('Spec version:', version.specVersion.toNumber());
console.log('Impl version:', version.implVersion.toNumber());
console.log('Transaction version:', version.transactionVersion.toNumber());

// Get version at a specific block
const blockHash = await api.rpc.chain.getBlockHash(1000000);
const historicalVersion = await api.rpc.state.getRuntimeVersion(blockHash);
console.log('Historical spec version:', historicalVersion.specVersion.toNumber());

await api.disconnect();
```

```python
import requests

def get_runtime_version(block_hash=None):
    url = 'https://api-flop-testnet.n.dwellir.com/YOUR_API_KEY'
    params = [block_hash] if block_hash else []

    payload = {
        'jsonrpc': '2.0',
        'method': 'state_getRuntimeVersion',
        'params': params,
        'id': 1
    }

    response = requests.post(url, json=payload)
    return response.json()['result']

version = get_runtime_version()
print(f"Spec: {version['specName']} v{version['specVersion']}")
print(f"Impl: {version['implName']} v{version['implVersion']}")
print(f"Transaction version: {version['transactionVersion']}")
print(f"Supported APIs: {len(version['apis'])}")
```

```rust
use subxt::{OnlineClient, PolkadotConfig};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let api = OnlineClient::<PolkadotConfig>::from_url(
        "wss://api-flop-testnet.n.dwellir.com/YOUR_API_KEY"
    ).await?;

    let version = api.rpc()
        .state_get_runtime_version(None)
        .await?;

    println!("Spec name: {}", version.spec_name);
    println!("Spec version: {}", version.spec_version);
    println!("Transaction version: {}", version.transaction_version);

    Ok(())
}
```

## Common Use Cases

### 1. Runtime Upgrade Monitor

Detect runtime upgrades on FLOP 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;
}
```

## Related Methods

- [`state_getMetadata`](https://www.dwellir.com/docs/flop/state_getMetadata) - Get full runtime metadata for decoding
- [`system_version`](https://www.dwellir.com/docs/flop/system_version) - Get node software version
- [`chain_subscribeFinalizedHeads`](https://www.dwellir.com/docs/flop/chain_subscribeFinalizedHeads) - Subscribe to detect upgrade blocks
