You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 18, 2024. It is now read-only.
This package is deprecated alongside ethers-rs, and will no longer be maintained.
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.ioethers-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]asyncfnmain() -> Result<()>{// Connect to the networklet provider = Provider::<Http>::try_from("https://mainnet.eth.aragon.network")?;// This is your searcher identitylet bundle_signer = LocalWallet::new(&mutthread_rng());// This signs transactionslet wallet = LocalWallet::new(&mutthread_rng());// Add signer and Flashbots middlewarelet 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 receiptlet 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(())}