Created
October 18, 2024 15:30
-
-
Save Aviksaikat/e6ea6402ef523e2ef6bdf0e12dde2c0e to your computer and use it in GitHub Desktop.
Get pending transactions using Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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