24 releases (14 breaking)

0.15.0 Jan 24, 2024
0.14.0 Aug 14, 2023
0.13.1 May 19, 2023
0.13.0 Mar 17, 2023
0.6.0 Oct 18, 2021

#1 in #flashbots

Download history 38/week @ 2024-07-01 19/week @ 2024-07-08 57/week @ 2024-07-15 72/week @ 2024-07-22 565/week @ 2024-07-29 54/week @ 2024-08-05 43/week @ 2024-08-12 84/week @ 2024-08-19 201/week @ 2024-08-26 39/week @ 2024-09-02 84/week @ 2024-09-09 94/week @ 2024-09-16 122/week @ 2024-09-23 26/week @ 2024-09-30 33/week @ 2024-10-07 21/week @ 2024-10-14

216 downloads per month
Used in 2 crates

MIT license

66KB
1K SLoC

Ethers Flashbots

CI Status Crates.io Docs.rs

An Ethers middleware to send transactions as Flashbots bundles.

Installation

Add ethers-flashbots to your Cargo.toml.

# This is the development version, for the stable release refer
# to crates.io
ethers-flashbots = { git = "https://github.com/onbjerg/ethers-flashbots" }

Usage

use eyre::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<()> {
    // Connect to the network
    let provider = Provider::<Http>::try_from("https://mainnet.eth.aragon.network")?;

    // This is your searcher identity
    let bundle_signer = LocalWallet::new(&mut thread_rng());
    // This signs transactions
    let wallet = LocalWallet::new(&mut thread_rng());

    // Add signer and Flashbots middleware
    let client = SignerMiddleware::new(
        FlashbotsMiddleware::new(
            provider,
            Url::parse("https://relay.flashbots.net")?,
            bundle_signer,
        ),
        wallet,
    );

    // Pay Vitalik using a Flashbots bundle!
    let tx = TransactionRequest::pay("vitalik.eth", 100);
    let pending_tx = client.send_transaction(tx, None).await?;

    // Get the receipt
    let receipt = pending_tx
        .await?
        .ok_or_else(|| eyre::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).

Make sure to add your changes to the "Unreleased" section of the changelog.

Donate

If you would like to support me in my open source journey feel free to send me some Eth or tokens (anything accepted) at bjerg.eth. I appreciate it! 🙇

Dependencies

~25–42MB
~795K SLoC