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?
- By the way, I find if I don't specify the subxt as
subxt = { version="0.27.0", default-features = false, features = ["jsonrpsee-web"] }
in myCargo.toml
, it seem like impossible to work withYew.rs
.And if i set subxt assubxt = { version="0.27.0", default-features = false, features = ["jsonrpsee-web"] }
in myCargo.toml
, theOnlineClient::<PolkadotConfig>::new().await.unwrap();
also throw error.
no function or associated item named `new` found for struct `OnlineClient` in the current scope
Can someone answer this question for me?
features = ["jsonrpsee-web"]
you won't be able to use the new() or from_url() functions as those only get compiled withfeatures = ["jsonrpsee-ws"]
. you can check it here github.com/paritytech/subxt/blob/…