2020-05-23 00:01:20 +00:00
|
|
|
use ethers::providers::{Provider, ProviderTrait};
|
|
|
|
use ethers::types::{BlockNumber, UnsignedTransaction};
|
2020-05-24 14:41:12 +00:00
|
|
|
use ethers::wallet::MainnetWallet;
|
2020-05-23 00:01:20 +00:00
|
|
|
use std::convert::TryFrom;
|
|
|
|
use std::str::FromStr;
|
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> Result<(), failure::Error> {
|
|
|
|
let provider = Provider::try_from("http://localhost:8545")?;
|
2020-05-24 14:41:12 +00:00
|
|
|
let client = MainnetWallet::from_str(
|
2020-05-23 00:01:20 +00:00
|
|
|
"d8ebe1e50cfea1f9961908d9df28e64bb163fee9ee48320361b2eb0a54974269",
|
|
|
|
)?
|
|
|
|
.connect(&provider);
|
|
|
|
|
|
|
|
let nonce = provider
|
2020-05-24 14:41:12 +00:00
|
|
|
.get_transaction_count(client.signer.address, None)
|
2020-05-23 00:01:20 +00:00
|
|
|
.await?;
|
2020-05-24 14:41:12 +00:00
|
|
|
|
2020-05-23 00:01:20 +00:00
|
|
|
let tx = UnsignedTransaction {
|
|
|
|
to: Some("986eE0C8B91A58e490Ee59718Cca41056Cf55f24".parse().unwrap()),
|
|
|
|
gas: 21000.into(),
|
|
|
|
gas_price: 100000.into(),
|
|
|
|
value: 10000.into(),
|
|
|
|
input: vec![].into(),
|
|
|
|
nonce,
|
|
|
|
};
|
|
|
|
|
2020-05-24 14:41:12 +00:00
|
|
|
let tx = client.send_transaction(tx).await?;
|
2020-05-23 00:01:20 +00:00
|
|
|
|
2020-05-24 14:41:12 +00:00
|
|
|
let tx = client.get_transaction(tx.hash).await?;
|
2020-05-23 00:01:20 +00:00
|
|
|
|
|
|
|
println!("{}", serde_json::to_string(&tx)?);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|