2020-05-27 20:43:02 +00:00
|
|
|
use anyhow::Result;
|
2020-05-31 16:20:08 +00:00
|
|
|
use ethers::prelude::*;
|
2020-05-27 20:43:02 +00:00
|
|
|
use std::convert::TryFrom;
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> Result<()> {
|
|
|
|
// connect to the network
|
2020-06-02 10:58:48 +00:00
|
|
|
let provider = Provider::<Http>::try_from(
|
|
|
|
"https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27",
|
|
|
|
)?;
|
2020-05-27 20:43:02 +00:00
|
|
|
|
|
|
|
// create a wallet and connect it to the provider
|
2020-10-02 08:41:16 +00:00
|
|
|
let wallet = "dcf2cbdd171a21c480aa7f53d77f31bb102282b3ff099c78e3118b37348c72f7"
|
|
|
|
.parse::<LocalWallet>()?;
|
2020-10-08 15:56:36 +00:00
|
|
|
let client = SignerMiddleware::new(provider, wallet);
|
2020-05-27 20:43:02 +00:00
|
|
|
|
|
|
|
// craft the transaction
|
|
|
|
let tx = TransactionRequest::new().to("vitalik.eth").value(100_000);
|
|
|
|
|
|
|
|
// send it!
|
2021-07-06 08:06:18 +00:00
|
|
|
let receipt = client
|
|
|
|
.send_transaction(tx, None)
|
|
|
|
.await?
|
|
|
|
.await?
|
|
|
|
.ok_or_else(|| anyhow::format_err!("tx dropped from mempool"))?;
|
2020-06-15 12:40:06 +00:00
|
|
|
let tx = client.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(())
|
|
|
|
}
|