#bundle #middleware #transaction #flashbots #ethers #send #ethers-rs

ethers-flashbots

Flashbots 中间件用于 ethers-rs

24 个版本 (14 个破坏性更新)

0.15.0 2024年1月24日
0.14.0 2023年8月14日
0.13.1 2023年5月19日
0.13.0 2023年3月17日
0.6.0 2021年10月18日

#317 in 神奇豆子

Download history 20/week @ 2024-04-19 44/week @ 2024-04-26 66/week @ 2024-05-03 57/week @ 2024-05-10 48/week @ 2024-05-17 62/week @ 2024-05-24 78/week @ 2024-05-31 86/week @ 2024-06-07 114/week @ 2024-06-14 72/week @ 2024-06-21 30/week @ 2024-06-28 28/week @ 2024-07-05 45/week @ 2024-07-12 81/week @ 2024-07-19 542/week @ 2024-07-26 72/week @ 2024-08-02

每月下载量:743
用于 2 crates

MIT 许可证

66KB
1K SLoC

Ethers Flashbots

CI Status Crates.io Docs.rs

一个用于将交易作为 Flashbots 打包发送的 Ethers 中间件。

安装

ethers-flashbots 添加到您的 Cargo.toml 文件中。

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

用法

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(())
}

查看 示例 了解更深入的示例。

贡献

欢迎提交拉取请求。对于重大更改,请首先创建一个问题来讨论您想进行更改的内容。

请确保测试和代码检查通过(cargo test && cargo clippy -- -D clippy::all && cargo fmt -- --check)。

确保将您的更改添加到更改日志的 "未发布" 部分。

捐赠

如果您想支持我在开源道路上的旅程,请随时向我发送一些 Eth 或代币(接受任何东西)到 bjerg.eth。感谢您!🙇

依赖项

~25–45MB
~800K SLoC