forked from onbjerg/ethers-flashbots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple.rs
42 lines (35 loc) · 1.24 KB
/
simple.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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<()> {
// 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(|| 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(())
}