Ethers Flashbots

An Ethers middleware to send transactions as Flashbots bundles.
Installation
Add ethers-flashbots to your Cargo.toml.
ethers-flashbots = { git = "https://github.com/onbjerg/ethers-flashbots" }
Usage
use anyhow::Result;
use ethers::core::rand::thread_rng;
use ethers::prelude::*;
use ethers_flashbots::*;
use std::convert::TryFrom;
use url::Url;
#[tokio::main]
async fn main() -> Result<()> {
let provider = Provider::<Http>::try_from("https://mainnet.eth.aragon.network")?;
let bundle_signer = LocalWallet::new(&mut thread_rng());
let wallet = LocalWallet::new(&mut thread_rng());
let client = SignerMiddleware::new(
FlashbotsMiddleware::new(
provider,
Url::parse("https://relay.flashbots.net")?,
bundle_signer,
),
wallet,
);
let tx = TransactionRequest::pay("vitalik.eth", 100);
let pending_tx = client.send_transaction(tx, None).await?;
let receipt = pending_tx
.await?
.ok_or_else(|| anyhow::format_err!("tx not included"))?;
let tx = client.get_transaction(receipt.transaction_hash).await?;
println!("Sent transaction: {}\n", serde_json::to_string(&tx)?);
println!("Receipt: {}\n", serde_json::to_string(&receipt)?);
Ok(())
}
See the examples for more in-depth examples.
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure that the tests and lints pass (cargo test && cargo clippy -- -D clippy::all && cargo fmt -- --check).