Git Product home page Git Product logo

alloy-flashbots's Introduction

Alloy Flashbots

An Alloy transport to send transaction bundles via Flashbots.

Installation

Add alloy-flashbots to your Cargo.toml.

alloy-flashbots = { git = "https://github.com/leruaa/alloy-flashbots" }

Usage

use std::env;

use alloy_flashbots::{
    rpc::{Inclusion, SendBundleRequest},
    FlashbotsLayer, FlashbotsProviderExt, FlashbotsTransactionBuilderExt,
};
use alloy_primitives::{address, U256};
use alloy::network::{Ethereum, EthereumSigner};
use alloy::providers::ProviderBuilder;
use alloy::rpc::client::RpcClient;
use alloy::rpc::types::eth::TransactionRequest;
use alloy::signers::LocalWallet;
use anyhow::Result;
use dotenv::dotenv;

#[tokio::main]
async fn main() -> Result<()> {
    dotenv().ok();
    let eth_rpc = env::var("ETH_HTTP_RPC")?;

    // This is your searcher identity
    let bundle_signer = LocalWallet::random();

    // This signs transactions
    let tx_signer = EthereumSigner::from(LocalWallet::random());

    // Build a provider with Flashbots
    let provider = ProviderBuilder::new()
        .with_recommended_fillers()
        .signer(tx_signer.clone())
        .on_http_with_flashbots(eth_rpc.parse()?, bundle_signer.clone());

    // Pay Vitalik using a Flashbots bundle!
    let tx = TransactionRequest::default()
        .from(tx_signer.default_signer_address())
        .to(Some(address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045"))) // vitalik.eth
        .value(U256::from(1000000000));

    // Build a bundle...
    let bundle = SendBundleRequest {
        bundle_body: vec![provider.build_bundle_item(tx, false).await?],
        inclusion: Inclusion::at_block(provider.get_block_number().await? + 1),
        ..Default::default()
    };

    // ... and send it!
    let response = provider.send_bundle(bundle).await?;

    println!("Bundle hash: {}", response.bundle_hash);

    Ok(())
}

TODO

  • Extension trait
  • Reqwest HTTP transport
  • Hyper HTTP transport
  • Rewrite RPC types from mev-share-rs ones that depends on ethers
  • Add a method to build a BundleItem from a TransactionRequest

Credits

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.