Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

add example #2546

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/subscriptions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }

serde.workspace = true
serde_json.workspace = true

serde = { version = "1.0.183", features = ["derive"] }
serde_json = "1.0"
eyre.workspace = true
32 changes: 32 additions & 0 deletions examples/subscriptions/examples/txpool_inspect.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use ethers::providers::{Http, Middleware, Provider};
use ethers::types::{TxpoolInspect, TxpoolInspectSummary, H160};
use eyre::Result;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;

#[derive(Serialize, Deserialize, Debug)]
struct TxpoolInspectData {
#[serde(rename = "queued")]
queued: BTreeMap<H160, BTreeMap<String, TxpoolInspectSummary>>,
#[serde(rename = "pending")]
pending: BTreeMap<H160, BTreeMap<String, TxpoolInspectSummary>>,
}

#[tokio::main]
async fn main() -> Result<()> {
let provider = Provider::<Http>::try_from("https://bsc-dataseed2.defibit.io")?;
let inspect: TxpoolInspect = provider.txpool_inspect().await?;

let data = TxpoolInspectData {
queued: inspect.queued.clone(),
pending: inspect.pending.clone(),
};

// Serialize the data to JSON format
let json_data = serde_json::to_string_pretty(&data)?;

// Print the JSON data
println!("{}", json_data);

Ok(())
}