Skip to content

Instantly share code, notes, and snippets.

@Aviksaikat
Created October 18, 2024 15:30
Show Gist options
  • Save Aviksaikat/e6ea6402ef523e2ef6bdf0e12dde2c0e to your computer and use it in GitHub Desktop.
Save Aviksaikat/e6ea6402ef523e2ef6bdf0e12dde2c0e to your computer and use it in GitHub Desktop.
Get pending transactions using Rust
use web3::transports::WebSocket;
use web3::Web3;
def main() {
let rpc_url: String = "http://localhost:8545" //"Your RPC URL"
// Initialize WebSocket transport
let ws = WebSocket::new(&rpc_url).await?;
let w3 = Web3::new(ws);
info!("Successfully connected to WebSocket RPC.");
debug!("Subscribing to pending transactions...");
let filter = w3.eth_filter().create_pending_transactions_filter().await?;
let pending_txs: Vec<H256> = filter.poll().await?.unwrap();
println!("Pending Transactions {:?}", pending_txs);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment