state_getRuntimeVersion - Bridge Hub RPC Method
Get the runtime version on Bridge Hub. Essential for compatibility checking, upgrade detection, and transaction construction on Polkadot's trustless bridging parachain with $75M+ TVL via Snowbridge to Ethereum.
Returns the runtime version information for Bridge Hub, including the spec name, spec version, implementation version, and supported API versions.
Why Bridge Hub? Build on Polkadot's trustless bridging parachain with $75M+ TVL via Snowbridge to Ethereum with on-chain BEEFY/Beacon light clients (no multisigs), 100+ ERC-20 tokens supported, 24+ parachain integrations, and 1-2 minute transfer times.
When to Use This Method
state_getRuntimeVersion is essential for cross-chain developers, bridge operators, and teams requiring trustless Ethereum-Polkadot transfers:
- Version Checking — Verify runtime compatibility before constructing transactions on Bridge Hub
- Upgrade Detection — Monitor for runtime upgrades that may change chain behavior for trustless ETH and ERC-20 bridging, cross-chain messaging, and parachain-to-Ethereum asset transfers
- Transaction Construction — Include the correct
specVersionandtransactionVersionin 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 Bridge Hub in real time:
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:
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:
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 Code | Description | Solution |
|---|---|---|
| -32603 | Internal error | Node may be syncing — retry with backoff |
| -32602 | Invalid params | Verify block hash format is valid hex with 0x prefix |
| -32601 | Method not found | Verify the node supports this RPC method |
| -32005 | Rate limit exceeded | Implement client-side rate limiting |
Related Methods
state_getMetadata— Get full runtime metadata for decodingsystem_version— Get node software versionchain_subscribeFinalizedHeads— Subscribe to detect upgrade blocks
state_getMetadata
Get runtime metadata on Bridge Hub. Essential for decoding storage, building extrinsics, and discovering available pallets and calls on Polkadot's trustless bridging parachain with $75M+ TVL via Snowbridge to Ethereum.
state_call
Call a runtime API function on Bridge Hub. Execute on-chain computations like account nonce lookups, fee estimation, and custom runtime logic without submitting a transaction.