How to use subxt in yew.rs font-end app #864
-
Here is test demo, but always fail to run.
[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"] }
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
I followed the steps exactly in the official documentation
What steps I forgot and need to do? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Sounds like the
|
Beta Was this translation helpful? Give feedback.
Sounds like the
metadata.scale
file is using an older metadata version based on this errorCould not decode
RuntimeMetadata, variant doesn't exist
.subxt
version 0.27 is usingframe-metadata: 15.2.0
which would only support v14 chain metadata. Some chains are using v15 now. The currentsubxt
0.31 is using a newerframe-metadata
that supports v15 chain metadata. That might fix your issue.