2020-10-02 08:41:16 +00:00
|
|
|
#[tokio::main]
|
|
|
|
#[cfg(feature = "yubi")]
|
2021-11-05 17:58:03 +00:00
|
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
2020-10-02 08:41:16 +00:00
|
|
|
use ethers::{prelude::*, utils::parse_ether};
|
|
|
|
use yubihsm::{Connector, Credentials, UsbConfig};
|
|
|
|
|
|
|
|
// Connect over websockets
|
|
|
|
let provider = Provider::new(Ws::connect("ws://localhost:8545").await?);
|
|
|
|
|
|
|
|
// We use USB for the example, but you can connect over HTTP as well. Refer
|
|
|
|
// to the [YubiHSM](https://docs.rs/yubihsm/0.34.0/yubihsm/) docs for more info
|
|
|
|
let connector = Connector::usb(&UsbConfig::default());
|
|
|
|
// Instantiate the connection to the YubiKey. Alternatively, use the
|
|
|
|
// `from_key` method to upload a key you already have, or the `new` method
|
|
|
|
// to generate a new keypair.
|
|
|
|
let wallet = YubiWallet::connect(connector, Credentials::default(), 0);
|
2020-10-08 15:56:36 +00:00
|
|
|
let client = SignerMiddleware::new(provider, wallet);
|
2020-10-02 08:41:16 +00:00
|
|
|
|
|
|
|
// Create and broadcast a transaction (ENS enabled!)
|
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-10-02 08:41:16 +00:00
|
|
|
|
|
|
|
// Get the receipt
|
2020-12-17 11:26:01 +00:00
|
|
|
let _receipt = pending_tx.confirmations(3).await?;
|
2020-10-02 08:41:16 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(feature = "yubi"))]
|
|
|
|
fn main() {}
|