state_getMetadata - JSON-RPC Method
Description#
Retrieves the SCALE-encoded runtime metadata for Enjin Matrix. SDKs and indexers decode this blob to discover pallets, storage items, extrinsics, and RPC interfaces. Refresh metadata whenever state_getRuntimeVersion reports a higher specVersion.
Parameters#
| Parameter | Type | Required | Description |
|---|---|---|---|
blockHash | string | null | No | Block hash for historical metadata; null returns the latest |
Returns#
| Field | Type | Description |
|---|---|---|
result | string | Hex-encoded SCALE metadata blob |
Request Example#
{
"jsonrpc": "2.0",
"method": "state_getMetadata",
"params": [],
"id": 1
}
Response Example (truncated)#
{
"jsonrpc": "2.0",
"result": "0x6d6574610c02000053657373696f6e0008436f6e73656e737573...",
"id": 1
}
Code Examples#
- cURL
- Python
- JavaScript
curl https://api-enjin-matrixchain.n.dwellir.com/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "state_getMetadata",
"params": [],
"id": 1
}'
import json
import requests
from scalecodec import ScaleBytes, MetadataDecoder
resp = requests.post(
"https://api-enjin-matrixchain.n.dwellir.com/YOUR_API_KEY",
headers={"Content-Type": "application/json"},
data=json.dumps({
"jsonrpc": "2.0",
"method": "state_getMetadata",
"params": [],
"id": 1,
}),
timeout=20,
)
metadata_hex = resp.json()["result"]
decoder = MetadataDecoder(ScaleBytes(metadata_hex))
metadata = decoder.decode()
print(metadata['metadata']['version'])
import { ApiPromise, WsProvider } from '@polkadot/api';
const api = await ApiPromise.create({
provider: new WsProvider('wss://api-enjin-matrixchain.n.dwellir.com/YOUR_API_KEY')
});
const metadata = await api.rpc.state.getMetadata();
console.log(metadata.asLatest.pallets.length);
Implementation Notes#
- Cache metadata keyed by
specVersionto avoid redundant downloads across services. - When using Polkadot.js or SubXT, metadata is fetched automatically on connection, but manual retrieval is helpful for offline codegen.
- Canary networks may expose new pallets ahead of mainnet—compare metadata diffs in staging before enabling features in production.