state_getMetadata
Description
Returns the latest runtime metadata as a SCALE-encoded blob. Decode this (or use scale-info
aware libraries) to understand pallets, storage layouts, and custom RPC types introduced by Bifrost upgrades.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
blockHash | string | No | Block hash to fetch historical metadata |
Returns
SCALE-encoded metadata blob (hex string).
Request Example
{
"jsonrpc": "2.0",
"method": "state_getMetadata",
"params": [],
"id": 1
}
Response Example
{
"jsonrpc": "2.0",
"result": "0x6d6574610c010000000100...",
"id": 1
}
Code Examples
JavaScript (polkadot.js)
const metadata = await api.rpc.state.getMetadata();
console.log('Spec version:', metadata.asLatest.version.toNumber());
Python (py-substrate-interface)
metadata_scale = substrate.rpc_request('state_getMetadata', [])["result"]
with open('bifrost_metadata.scale', 'w') as f:
f.write(metadata_scale)
Usage Notes
- After runtime upgrades (e.g., specVersion 21001), refresh metadata to decode new pallets like
Hyperbridge
,FlexibleFee
, or omnipool updates. - Tools such as
subxt
orpolkadot-js/api
automatically refresh metadata when the runtime version increases.