2020-09-20 18:27:00 +00:00
|
|
|
#[tokio::main]
|
2020-09-23 08:04:54 +00:00
|
|
|
#[cfg(feature = "ledger")]
|
2020-09-24 21:33:09 +00:00
|
|
|
async fn main() -> anyhow::Result<()> {
|
2020-09-23 08:04:54 +00:00
|
|
|
use ethers::{prelude::*, utils::parse_ether};
|
|
|
|
|
2020-09-20 18:27:00 +00:00
|
|
|
// Connect over websockets
|
|
|
|
let provider = Provider::new(Ws::connect("ws://localhost:8545").await?);
|
|
|
|
// Instantiate the connection to ledger with Ledger Live derivation path and
|
|
|
|
// the wallet's index. Alternatively, you may use Legacy with the wallet's
|
|
|
|
// index or supply the full HD path string. You may also provide the chain_id
|
|
|
|
// (here: mainnet) for EIP155 support.
|
2021-07-29 20:22:25 +00:00
|
|
|
let ledger = Ledger::new(HDPath::LedgerLive(0), 1).await?;
|
2020-10-08 15:56:36 +00:00
|
|
|
let client = SignerMiddleware::new(provider, ledger);
|
2020-09-20 18:27:00 +00:00
|
|
|
|
|
|
|
// Create and broadcast a transaction (ENS enabled!)
|
|
|
|
// (this will require confirming the tx on the device)
|
2021-10-29 12:29:35 +00:00
|
|
|
let tx = TransactionRequest::new().to("vitalik.eth").value(parse_ether(10)?);
|
2020-12-17 11:26:01 +00:00
|
|
|
let pending_tx = client.send_transaction(tx, None).await?;
|
2020-09-20 18:27:00 +00:00
|
|
|
|
|
|
|
// Get the receipt
|
2020-12-17 11:26:01 +00:00
|
|
|
let _receipt = pending_tx.confirmations(3).await?;
|
2020-09-20 18:27:00 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
2020-09-23 08:04:54 +00:00
|
|
|
|
|
|
|
#[cfg(not(feature = "ledger"))]
|
|
|
|
fn main() {}
|