Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
decentration opened this issue Jul 1, 2024 · 1 comment
Open

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

decentration opened this issue Jul 1, 2024 · 1 comment

Comments

@decentration
Copy link

decentration commented Jul 1, 2024

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.

@decentration
Copy link
Author

@jacogr can you help on this issue?

trying to know the way to parse "Runtime Calls"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant