3

I am using subxt to get the list of parachains on the Polkadot network. Firstly I used the subxt-cli tool to download the metadata:

subxt metadata --url https://rpc.polkadot.io:443 -f bytes > polkadot-metadata.scale

The file looks fine:

#[subxt::subxt(runtime_metadata_path = "metadata/polkadot_metadata.scale")]
pub mod polkadot {}

And then I query the storage to retrieve the parachains:

let storage_query = polkadot::storage().paras().parachains();

let result = api
        .storage()
        .at_latest()
        .await?
        .fetch(&storage_query)
        .await?;

But when I run it I get an error:

Error: Metadata(PalletNotFound)

What am I doing wrong here? How can I check that I have the correct metadata? Or the list of pallets I can query?

The query on PolkadotJS is the following:

enter image description here

1 Answer 1

3

First of all, thanks for asking about this topic

Any metadata on the disk can be further inspected with the use of subxt-cli, we've also added some new features that allows users to quickly explore the metadata information (in this PR). However, you can still go back and forth between the binary format and the JSON format with older subxt versions.

As you mentioned above, the metadata is downloaded as

cargo run --release -p subxt-cli -- metadata --url https://rpc.polkadot.io:443 -f bytes > artifacts/test_metadata.scale

We can see all the pallets present in the metadata by doing a

cargo run --release -p subxt-cli -- explore --file artifacts/test_metadata.scale

..
    ParachainsOrigin
    Paras
    ParasDisputes
..

Then we can see the storage entries of the Paras pallet with the following

cargo run --release -p subxt-cli -- explore --file artifacts/test_metadata.scale Paras storage

..
    ParaLifecycles
    Parachains
    PastCodeHash
..

Using the same code lines from your question I do get the output:

cargo run --example stack_8663                                                                                                                                                                                                                                     14:02:55

polkadot::storage().paras().parachains(): Some([Id(1000), Id(1001), Id(1002), Id(2000), Id(2002), Id(2004), Id(2006), Id(2007), Id(2008), Id(2011), Id(2012), Id(2013), Id(2019), Id(2021), Id(2026), Id(2027), Id(2030), Id(2031), Id(2032), Id(2034), Id(2035), Id(2037), Id(2039), Id(2040), Id(2043), Id(2046), Id(2048), Id(2051), Id(2052), Id(2053), Id(2055), Id(2056), Id(2058), Id(2086), Id(2090), Id(2091), Id(2092), Id(2093), Id(2094), Id(2097), Id(2101), Id(2104), Id(2106), Id(3333), Id(3334), Id(3336)])

You can give my example a go from the branch lexnv/stack_8663 (commit 6c4c58e0):

    // Create a new API client, configured to talk to Polkadot nodes.
    let api = OnlineClient::<PolkadotConfig>::from_url("wss://rpc.polkadot.io:443").await?;

    // Build the query.
    let storage_query = polkadot::storage().paras().parachains();

    // Fetch the result.
    let result = api
        .storage()
        .at_latest()
        .await?
        .fetch(&storage_query)
        .await?;

    println!("polkadot::storage().paras().parachains(): {result:?}");

Further Debugging

The Error: Metadata(PalletNotFound) suggests that the pallet Paras (in this case I presume) is missing. There are two possibilities here:

  • Is your metadata in sync? (ie, you may be using older metadata -- please check that the path is correct and regenerate the metadata as above)
  • Are you doing any other subxt calls? (ie, you may call other queries for storage / tx with other pallets, pallets that may no longer be present in the chain)

Another thing worth mentioning is how you build your subxt client (although not that relevant -- I construct the client with OnlineClient::<PolkadotConfig>::from_url("wss://rpc.polkadot.io:443").await?).

1
  • Brilliant answer thanks! Constructing the client with: let api = OnlineClient::<PolkadotConfig>::from_url("wss://rpc.polkadot.io:443").await?; works!!
    – Alex Bean
    Commented May 29, 2023 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.