rust-web3
rust-web3 copied to clipboard
How to get transactions from the specified from_address and to_address
I looked it up with the following code, but it was too slow
let latest_block = web3
.eth()
.block(BlockId::Number(BlockNumber::Latest))
.await
.unwrap()
.unwrap();
for transaction_hash in latest_block.transactions {
let tx = match web3
.eth()
.transaction(TransactionId::Hash(transaction_hash))
.await
{
Ok(Some(tx)) => tx,
_ => {
println!("An error occurred");
continue;
}
};
let from_addr = tx.from.unwrap_or(H160::zero());
let to_addr = tx.to.unwrap_or(H160::zero());
println!(
"[{}] from {}, to {}, value {}, gas {}, gas price {:?}",
tx.transaction_index.unwrap_or(U64::from(0)),
from_addr,
to_addr,
tx.value,
tx.gas,
tx.gas_price,
);
}