chore: add example for ledger
This commit is contained in:
parent
95fcbe5240
commit
8ff9a894c0
|
@ -56,7 +56,6 @@ pub enum INS {
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
pub enum P1 {
|
pub enum P1 {
|
||||||
CONFIRM = 0x01,
|
|
||||||
NON_CONFIRM = 0x00,
|
NON_CONFIRM = 0x00,
|
||||||
MORE = 0x80,
|
MORE = 0x80,
|
||||||
}
|
}
|
||||||
|
@ -65,6 +64,5 @@ pub enum P1 {
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
pub enum P2 {
|
pub enum P2 {
|
||||||
CHAINCODE = 0x01,
|
|
||||||
NO_CHAINCODE = 0x00,
|
NO_CHAINCODE = 0x00,
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,9 @@ mod wallet;
|
||||||
pub use wallet::Wallet;
|
pub use wallet::Wallet;
|
||||||
|
|
||||||
#[cfg(feature = "ledger")]
|
#[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;
|
mod nonce_manager;
|
||||||
pub(crate) use nonce_manager::NonceManager;
|
pub(crate) use nonce_manager::NonceManager;
|
||||||
|
|
|
@ -40,6 +40,7 @@ core = ["ethers-core"]
|
||||||
contract = ["ethers-contract"]
|
contract = ["ethers-contract"]
|
||||||
providers = ["ethers-providers"]
|
providers = ["ethers-providers"]
|
||||||
signers = ["ethers-signers"]
|
signers = ["ethers-signers"]
|
||||||
|
ledger = ["ethers-signers/ledger"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ethers-contract = { version = "0.1.3", path = "../ethers-contract", optional = true }
|
ethers-contract = { version = "0.1.3", path = "../ethers-contract", optional = true }
|
||||||
|
|
|
@ -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(())
|
||||||
|
}
|
Loading…
Reference in New Issue