2020-05-26 11:00:56 +00:00
|
|
|
use anyhow::Result;
|
|
|
|
use ethers::{providers::HttpProvider, signers::MainnetWallet, types::TransactionRequest};
|
2020-05-23 00:01:20 +00:00
|
|
|
use std::convert::TryFrom;
|
|
|
|
|
|
|
|
#[tokio::main]
|
2020-05-26 11:00:56 +00:00
|
|
|
async fn main() -> Result<()> {
|
2020-05-24 16:14:27 +00:00
|
|
|
// connect to the network
|
2020-05-24 15:55:46 +00:00
|
|
|
let provider = HttpProvider::try_from("http://localhost:8545")?;
|
2020-05-24 16:14:27 +00:00
|
|
|
|
|
|
|
// create a wallet and connect it to the provider
|
2020-05-25 15:35:38 +00:00
|
|
|
let client = "dcf2cbdd171a21c480aa7f53d77f31bb102282b3ff099c78e3118b37348c72f7"
|
2020-05-24 18:34:56 +00:00
|
|
|
.parse::<MainnetWallet>()?
|
|
|
|
.connect(&provider);
|
2020-05-24 14:41:12 +00:00
|
|
|
|
2020-05-24 16:14:27 +00:00
|
|
|
// craft the transaction
|
2020-05-24 18:34:56 +00:00
|
|
|
let tx = TransactionRequest::new()
|
|
|
|
.send_to_str("986eE0C8B91A58e490Ee59718Cca41056Cf55f24")?
|
|
|
|
.value(10000);
|
2020-05-23 00:01:20 +00:00
|
|
|
|
2020-05-24 16:14:27 +00:00
|
|
|
// send it!
|
2020-05-25 15:35:38 +00:00
|
|
|
let hash = client.send_transaction(tx, None).await?;
|
2020-05-23 00:01:20 +00:00
|
|
|
|
2020-05-24 16:14:27 +00:00
|
|
|
// get the mined tx
|
2020-05-25 15:35:38 +00:00
|
|
|
let tx = client.get_transaction(hash).await?;
|
2020-05-23 00:01:20 +00:00
|
|
|
|
2020-05-24 20:27:51 +00:00
|
|
|
let receipt = client.get_transaction_receipt(tx.hash).await?;
|
|
|
|
|
2020-05-23 00:01:20 +00:00
|
|
|
println!("{}", serde_json::to_string(&tx)?);
|
2020-05-24 20:27:51 +00:00
|
|
|
println!("{}", serde_json::to_string(&receipt)?);
|
2020-05-23 00:01:20 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|