2022-06-01 15:22:39 +00:00
|
|
|
use ethers::{prelude::*, utils::Anvil};
|
2022-02-03 20:36:05 +00:00
|
|
|
use eyre::Result;
|
2020-05-27 20:43:02 +00:00
|
|
|
use std::convert::TryFrom;
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> Result<()> {
|
2021-08-30 11:00:30 +00:00
|
|
|
// fork mainnet
|
2022-06-01 15:22:39 +00:00
|
|
|
let anvil =
|
|
|
|
Anvil::new().fork("https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27").spawn();
|
|
|
|
let from = anvil.addresses()[0].clone();
|
2020-05-27 20:43:02 +00:00
|
|
|
// connect to the network
|
2022-06-01 15:22:39 +00:00
|
|
|
let provider = Provider::<Http>::try_from(anvil.endpoint()).unwrap().with_sender(from);
|
2020-05-27 20:43:02 +00:00
|
|
|
|
|
|
|
// craft the transaction
|
|
|
|
let tx = TransactionRequest::new().to("vitalik.eth").value(100_000);
|
|
|
|
|
|
|
|
// send it!
|
2021-08-30 11:00:30 +00:00
|
|
|
let receipt = provider
|
2021-07-06 08:06:18 +00:00
|
|
|
.send_transaction(tx, None)
|
|
|
|
.await?
|
|
|
|
.await?
|
2022-02-03 20:36:05 +00:00
|
|
|
.ok_or_else(|| eyre::format_err!("tx dropped from mempool"))?;
|
2021-08-30 11:00:30 +00:00
|
|
|
let tx = provider.get_transaction(receipt.transaction_hash).await?;
|
2020-05-27 20:43:02 +00:00
|
|
|
|
|
|
|
println!("{}", serde_json::to_string(&tx)?);
|
|
|
|
println!("{}", serde_json::to_string(&receipt)?);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|