1

Here is test demo, but always fail to run.

  • Cargo.toml
[dependencies]
yew = { version = "0.20.0", features = ["csr"] }
gloo = "0.8.0"
wasm-bindgen-futures = "0.4.32"
subxt = { version="0.27.0", default-features = false, features = ["jsonrpsee-web"] }
  • main.rs
use gloo::console::log;
// use sp_keyring::AccountKeyring;
use subxt::{OnlineClient, PolkadotConfig};
use wasm_bindgen_futures;
use yew::prelude::*;

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

#[function_component(App)]
fn app() -> Html {
    wasm_bindgen_futures::spawn_local(async move {
        let api = OnlineClient::<PolkadotConfig>::new().await.unwrap();
        log!("hello world");
    });
    html! {
      <>
          <h1 class="text-3xl font-bold underline bg-slate-100">{"Hello world!"}</h1>
      </>
    }
}

fn main() {
    yew::Renderer::<App>::new().render();
}

The problem is #[subxt::subxt(runtime_metadata_path = "metadata.scale")] pub mod polkadot {} always throw an error

error: Failed to decode metadata: Could not decode `RuntimeMetadataPrefixed.1`:
           Could not decode `RuntimeMetadata`, variant doesn't exist

I think I followed the steps exactly in the official documentation

  1. Build a local blockchain
  2. run cargo install subxt-cli
  3. run subxt metadata -f bytes > metadata.scale
  • What steps I forgot and need to do?
1
  • by changing the features to subxt = { version = "0.27.0", default-features = false, features = ["jsonrpsee-ws"] } and adding parity-scale-codec = { version = "3.4.0", default-features = false } to the Cargo.toml I can build the project, however, when I try to run I get an error thread 'main' panicked at 'cannot call wasm-bindgen imported functions on non-wasm targets'. I am not familiar with yew or wasm_bindgen so I can't answer futher.
    – Yeou
    Commented Mar 20, 2023 at 9:07

1 Answer 1

2
  1. Build a local blockchain
  2. run cargo install subxt-cli
  3. run subxt metadata -f bytes > metadata.scale

How are you building/starting a local blockchain node? The error error: Failed to decode metadata: Could not decode RuntimeMetadataPrefixed.1 implies that there is something wrong with your metadata.scale file.

Perhaps you ran into an error running subxt metadata -f bytes > metadata.scale and the file is empty or doesn't have the expected contents in (how big is it? Can you open it with a text editor?). Perhaps the node you started has some sort of issue. I'd need more information to be able to help with this.

1
  • Hmm thanks for spotting this; I just removed it!
    – jsdw
    Commented Apr 3, 2023 at 9:24

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.