Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to define a custom URL #364

Closed
kebab-mai-haddi opened this issue Dec 12, 2021 · 2 comments
Closed

Unable to define a custom URL #364

kebab-mai-haddi opened this issue Dec 12, 2021 · 2 comments

Comments

@kebab-mai-haddi
Copy link

kebab-mai-haddi commented Dec 12, 2021

I want to connect to a public network but while I do so using an API, it throws the error:

thread 'main' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime', /Users/aviralsrivastava/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.14.0/src/runtime/context.rs:54:26
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I set the URL and the port in a typical format in my code:

let api = ClientBuilder::new()
        .set_url("wss://pub.elara.patract.io:9944/statemine")
        .build()
        .await?
        .to_runtime_api::<polkadot::RuntimeApi<polkadot::DefaultConfig>>();

I tried to take a look at the source code for ClientBuilder:

let url = self.url.as_deref().unwrap_or("ws://127.0.0.1:9944");

The format is the same as in my code.

My MVC:

use subxt::ClientBuilder;

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

#[async_std::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    env_logger::init();

    let api = ClientBuilder::new()
        .set_url("wss://pub.elara.patract.io:9944/statemine")
        .build()
        .await?
        .to_runtime_api::<polkadot::RuntimeApi<polkadot::DefaultConfig>>();

    let mut iter = api.storage().system().account_iter(None).await?;

    while let Some((key, account)) = iter.next().await? {
        println!("{}: {}", hex::encode(key), account.data.free);
    }
    Ok(())
}

My Cargo.toml:

[package]
name = "my-package"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
subxt = { git = "https://github.com/paritytech/subxt/" }
async-std = {version = "1.10.0", features = ["attributes"]}
env_logger = "0.9.0"
async-trait = "0.1.49"
bitvec = { version = "0.20.1", default-features = false, features = ["alloc"] }
codec = { package = "parity-scale-codec", version = "2", default-features = false, features = ["derive", "full", "bit-vec"] }
chameleon = "0.1.0"
scale-info = { version = "1.0.0", features = ["bit-vec"] }
futures = "0.3.13"
hex = "0.4.3"
jsonrpsee = { version = "0.5.1", features = ["macros", "ws-client", "http-client"] }
log = "0.4.14"
num-traits = { version = "0.2.14", default-features = false }
serde = { version = "1.0.124", features = ["derive"] }
serde_json = "1.0.64"
thiserror = "1.0.24"
url = "2.2.1"

How do I configure my own URL to use the subxt library?

@niklasad1
Copy link
Member

niklasad1 commented Dec 12, 2021

@kebab-mai-haddi

The URL is not the issue you have to use tokio 1.0 or async-std = { version = "1.9.0", features = ["attributes", "tokio1"] }

because the JSON-RPC client requires tokio 1.0 as runtime executor.

https://github.com/paritytech/subxt/blob/master/Cargo.toml#L46

@kebab-mai-haddi
Copy link
Author

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants