⚠️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

Description

Retrieves the runtime metadata for the Moonriver blockchain. Metadata contains essential information about the runtime's pallets, storage items, calls, events, errors, and types. This information is crucial for properly encoding transactions and decoding storage values.

Parameters

ParameterTypeRequiredDescription
blockHashstringNoHex-encoded block hash to query metadata at specific block. If omitted, uses the latest block

Returns

FieldTypeDescription
resultstringHex-encoded SCALE-encoded metadata

Request Example

{
"jsonrpc": "2.0",
"method": "state_getMetadata",
"params": [],
"id": 1
}

Response Example

{
"jsonrpc": "2.0",
"result": "0x6d6574610e7c1853797374656d1853797374656d04...",
"id": 1
}

Code Examples

# Get current metadata
curl https://api-moonriver.n.dwellir.com/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "state_getMetadata",
"params": [],
"id": 1
}'

# Get metadata at specific block
curl https://api-moonriver.n.dwellir.com/YOUR_API_KEY \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "state_getMetadata",
"params": ["0xa39d25f8cf7ad27e6a739dc15d4d013bdc48b6e2819bb74c72822a930adb5649"],
"id": 1
}'

Tip: Replace the sample block hash with a recent Moonriver finalized block from chain_getFinalizedHead.

Metadata Structure

Key Components

  1. Pallets: Modules that compose the runtime

    • Storage items
    • Callable functions (extrinsics)
    • Events
    • Errors
    • Constants
  2. Types Registry: Type definitions for encoding/decoding

  3. Extrinsic Format: Structure of transactions

  4. Runtime Version: Specification version and APIs

Common Pallets

PalletDescription
SystemCore blockchain functionality
BalancesNative token management
StakingValidator and nominator operations
DemocracyGovernance proposals and voting
IdentityOn-chain identity management
ProxyProxy account management
MultisigMulti-signature operations

Use Cases

  1. Transaction Construction: Encode calls with proper types
  2. Storage Decoding: Interpret storage query results
  3. Event Parsing: Decode events from blocks
  4. UI Generation: Build dynamic interfaces based on available calls
  5. Chain Analysis: Understand runtime capabilities and constraints

Working with Metadata

Decoding Metadata

// Using @polkadot/api
const api = await ApiPromise.create({ provider });

// Metadata is automatically handled
const pallets = api.runtimeMetadata.pallets;
pallets.forEach(pallet => {
console.log(`Pallet ${pallet.name}:`, {
storage: pallet.storage?.items.length || 0,
calls: pallet.calls?.length || 0,
events: pallet.events?.length || 0
});
});

Version Compatibility

// Check metadata version
const metadata = await api.rpc.state.getMetadata();
const version = metadata.version;

if (version < 14) {
console.warn('Metadata version outdated, some features may not work');
}

Notes

  • Metadata is SCALE-encoded and requires proper decoding
  • Metadata changes with runtime upgrades
  • Cache metadata for performance - it's large (typically 500KB+)
  • Different metadata versions have different structures
  • Always use matching metadata version for encoding/decoding