chore: add example for ledger

This commit is contained in:
Georgios Konstantopoulos 2020-09-20 21:27:00 +03:00
parent 95fcbe5240
commit 8ff9a894c0
4 changed files with 29 additions and 3 deletions

View File

@ -56,7 +56,6 @@ pub enum INS {
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[allow(non_camel_case_types)]
pub enum P1 {
CONFIRM = 0x01,
NON_CONFIRM = 0x00,
MORE = 0x80,
}
@ -65,6 +64,5 @@ pub enum P1 {
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[allow(non_camel_case_types)]
pub enum P2 {
CHAINCODE = 0x01,
NO_CHAINCODE = 0x00,
}

View File

@ -41,7 +41,9 @@ mod wallet;
pub use wallet::Wallet;
#[cfg(feature = "ledger")]
pub mod ledger;
mod ledger;
#[cfg(feature = "ledger")]
pub use ledger::{app::LedgerEthereum as Ledger, types::{LedgerError, DerivationType as HDPath}};
mod nonce_manager;
pub(crate) use nonce_manager::NonceManager;

View File

@ -40,6 +40,7 @@ core = ["ethers-core"]
contract = ["ethers-contract"]
providers = ["ethers-providers"]
signers = ["ethers-signers"]
ledger = ["ethers-signers/ledger"]
[dependencies]
ethers-contract = { version = "0.1.3", path = "../ethers-contract", optional = true }

25
ethers/examples/ledger.rs Normal file
View File

@ -0,0 +1,25 @@
use anyhow::Result;
use ethers::{utils::parse_ether, prelude::*};
#[tokio::main]
async fn main() -> Result<()> {
// 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.
let ledger = Ledger::new(HDPath::LedgerLive(0), Some(1)).await?;
let client = Client::new(provider, ledger).await?;
// Create and broadcast a transaction (ENS enabled!)
// (this will require confirming the tx on the device)
let tx = TransactionRequest::new()
.to("vitalik.eth")
.value(parse_ether(10)?);
let tx_hash = client.send_transaction(tx, None).await?;
// Get the receipt
let receipt = client.pending_transaction(tx_hash).confirmations(3).await?;
Ok(())
}