โš ๏ธBlast API (blastapi.io) ends Oct 31. Migrate to Dwellir and skip Alchemy's expensive compute units.
Switch Today โ†’
Skip to main content

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โ€‹

ParameterTypeRequiredDescription
blockHashstring | nullNoBlock hash for historical metadata; null returns the latest

Returnsโ€‹

FieldTypeDescription
resultstringHex-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โ€‹

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
}'

JavaScript (Polkadot.js)โ€‹

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);

Python (scale-codec)โ€‹

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'])

Implementation Notesโ€‹

  • Cache metadata keyed by specVersion to 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.