Skip to content

How to extract and parse runtime APIs from the metadata? #477

Open
@decentration

Description

@decentration

I am trying to find the correct way to parse api.call.metadata.metadata() so i can automatically render the "Runtime Calls" for the selected chain.

I am trying to get the runtime calls from the runtime metadata...

async function fetchRuntimeMetadata(api: ApiPromise) {
    const metadata = await api.call.metadata.metadata();
    const readableMetadata = hexToString(metadata.toString());

    console.log('readableMetadata',readableMetadata);
    return readableMetadata;
}

to convert the hex to string i naively flatten the object to a string, which makes it a big challenge to parse...

if i use the above, and try and decode the hex to string, i get this:

runtimeMetdata from queryMetadata: meta�
sp_corecrypto,AccountId32 [u8; 32] 0frame_system,AccountInfoNonce,AccountDatanonceNonce$consumers RefCount$providers RefCount,sufficients RefCountdata,AccountData<pallet_balancestypes,AccountDataBalancefreeBalance reservedBalancefrozenBalanceflags(ExtraFlags<pallet_balancestypes(ExtraFlagsu128 4frame_support dispatch@PerDispatchClassT$normal$T,operational$T$mandatory$T$(sp_weights$weight_v2Weight ref_time(u64(proof_size(u64(,,0<primitive_typesH256 [u8; 32]48(sp_runtimegenericdigestDigestlogs<<Vec<DigestItem><@@(sp_runtimegenericdigest(DigestItem(PreRuntimeDDConsensusEngineId4Vec<u8>$ConsensusDDConsensusEngineId4Vec<u8>SealDDConsensusEngineId4Vec<u8>Other4Vec<u8>dRuntimeEnvironmentUpdatedDHLL0frame_system,EventRecordEPT0phase)PhaseeventPEtopics�Vec<T>P@polkadot_runtime0RuntimeEvent�SystemTpframe_system::Event<Runtime>$Scheduler|�pallet_scheduler::Event<Runtime> Preimage�|pallet_preimage::Event<Runtime>
Indices�xpallet_indices::Event<Runtime> Balances�|pallet_balances::Event<Runtime>HTransactionPayment��pallet_transaction_payment::Event<Runtime> Staking�xpallet_staking::Event<Runtime> Offences�Xpallet_offences::EventSession�

how can i decode the metadata.metadata so that it is parsable?


Here is also the substrate stack exchange issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions