I have a working example using ethers-rs that fetches the latest block with full transactions and prints basic fields (block number, hash, timestamp, transactions count, and for each tx: hash, from, to, value in ETH, gas price, gas, nonce, and input length if present). I want to implement the same functionality using alloy 1.1.
Requirements:
- Use alloy 1.1 APIs.
- Connect to an HTTP RPC endpoint (e.g., https://eth.llamarpc.com).
- Fetch the latest block with full transactions included.
- Print the same fields as in the ethers example, including formatting value in ETH.
Questions:
- What are the recommended alloy crates and types to use for this (provider/client, block/tx types)?
- How to request “block with transactions” in alloy 1.1?
- How to format wei to ETH using alloy utilities?
- A minimal runnable Rust example (Tokio main) would be appreciated.
Notes:
Rust 1.91+ preferred.
Please include Cargo.toml dependencies for alloy 1.1.
use ethers::prelude::*; use eyre::Result; #[tokio::main] async fn main() -> Result { let provider = Provider::::try_from( "https://eth.llamarpc.com" )?; if let Some(block) = provider.get_block_with_txs(BlockNumber::Latest).await? { println!("block number: {}", block.number.unwrap()); println!("block hash: {:?}", block.hash.unwrap()); println!("timestamp: {}", block.timestamp); println!("transactions len: {}", block.transactions.len()); for (idx, tx) in block.transactions.iter().enumerate() { println!("\ntransaction #{}", idx + 1); println!(" hash: {:?}", tx.hash); println!(" from: {:?}", tx.from); println!(" to: {:?}", tx.to); println!(" value: {} ETH", ethers::utils::format_ether(tx.value)); println!(" Gas price: {}", tx.gas_price.unwrap_or_default()); println!(" Gas: {}", tx.gas); println!(" Nonce: {}", tx.nonce); if !tx.input.is_empty() { println!(" input len: {} bytes", tx.input.len()); } } } Ok(()) }