Rust
Last updated
Was this helpful?
Last updated
Was this helpful?
Create a new Rust project:
cargo new radius_quickstart
cd radius_quickstart
Add the following dependencies to your Cargo.toml
file:
[dependencies]
reqwest = { version = "0.11", features = ["json"] }
tokio = { version = "1", features = ["full"] }
serde_json = "1.0"
Replace the contents of src/main.rs
with the following code:
use reqwest::Client;
use serde_json::{json, Value};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let url = "https://rpc.testnet.tryradi.us/<YOUR-RPC-ENDPOINT>";
let client = Client::new();
let response = client.post(url)
.json(&json!({
"jsonrpc": "2.0",
"method": "eth_blockNumber",
"params": [],
"id": 1
}))
.send()
.await?;
let result: Value = response.json().await?;
println!("{}", result);
Ok(())
}
Run the code using the following command:
cargo run
Create a new Rust project:
cargo new radius_quickstart
cd radius_quickstart
Add the following dependencies to your Cargo.toml
file:
[dependencies]
alloy-provider = "0.9.2"
tokio = { version = "1.43.0", features = ["full"] }
Replace the contents of src/main.rs
with the following code:
use alloy_provider::{Provider, ProviderBuilder};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a new wallet client with custom RPC endpoint
let rpc_url = "https://rpc.testnet.tryradi.us/<YOUR-RPC-ENDPOINT>".parse()?;
let provider = ProviderBuilder::new().on_http(rpc_url);
// Get the current block number as a test
let block_number = provider.get_block_number().await?;
println!("Current block number: {}", block_number);
Ok(())
}
Run the code using the following command:
cargo run