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
- Build a local blockchain
- run
cargo install subxt-cli
- run
subxt metadata -f bytes > metadata.scale
- What steps I forgot and need to do?
subxt = { version = "0.27.0", default-features = false, features = ["jsonrpsee-ws"] }
and addingparity-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 errorthread '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.