Skip to content

Commit

Permalink
add eyre and update wallet examples
Browse files Browse the repository at this point in the history
  • Loading branch information
zerosnacks committed Mar 15, 2024
1 parent 5eaa6ab commit f02a16f
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/wallets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ alloy-signer-wallet = { workspace = true, features = ["mnemonic", "yubihsm"] }
alloy-sol-types.workspace = true
alloy-transport-http.workspace = true

rand.workspace = true
eyre.workspace = true
reqwest.workspace = true
serde.workspace = true
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
7 changes: 5 additions & 2 deletions examples/wallets/examples/ledger_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ use alloy_rpc_client::RpcClient;
use alloy_rpc_types::request::TransactionRequest;
use alloy_signer_ledger::{HDPath, LedgerSigner};
use alloy_transport_http::Http;
use eyre::Result;
use reqwest::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
async fn main() -> Result<()> {
// Instantiate the application by acquiring a lock on the Ledger device.
let signer = LedgerSigner::new(HDPath::LedgerLive(0), Some(1)).await?;

// Create a provider with the signer and the network.
let http = Http::<Client>::new("http://localhost:8545".parse()?);

// Initialize the provider.
let provider = ProviderBuilder::new()
.signer(EthereumSigner::from(signer))
.provider(RootProvider::new(RpcClient::new(http, true)));
Expand All @@ -32,7 +35,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Broadcast the transaction and wait for the receipt.
let receipt = provider.send_transaction(tx).await?.with_confirmations(3).get_receipt().await?;

println!("Send transaction: {:?}", receipt.transaction_hash.unwrap());
println!("Send transaction: {:?}", receipt.transaction_hash.unwrap_or_default());

Ok(())
}
3 changes: 2 additions & 1 deletion examples/wallets/examples/mnemonic_signer.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! Example of using `MnemonicBuilder` to access a wallet from a mnemonic phrase.

use alloy_signer_wallet::{coins_bip39::English, MnemonicBuilder};
use eyre::Result;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
async fn main() -> Result<()> {
let phrase = "work man father plunge mystery proud hollow address reunion sauce theory bonus";
let index = 0u32;
let password = "TREZOR123";
Expand Down
3 changes: 2 additions & 1 deletion examples/wallets/examples/private_key_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ use alloy_rpc_client::RpcClient;
use alloy_rpc_types::request::TransactionRequest;
use alloy_signer_wallet::LocalWallet;
use alloy_transport_http::Http;
use eyre::Result;
use reqwest::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
async fn main() -> Result<()> {
// Spin up an Anvil node.
let anvil = Anvil::new().block_time(1).spawn();

Expand Down
3 changes: 2 additions & 1 deletion examples/wallets/examples/sign_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

use alloy_signer::Signer;
use alloy_signer_wallet::LocalWallet;
use eyre::Result;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
async fn main() -> Result<()> {
// Setup up wallet.
let wallet = LocalWallet::random();

Expand Down
3 changes: 2 additions & 1 deletion examples/wallets/examples/sign_permit_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use alloy_primitives::{address, keccak256, U256};
use alloy_signer::Signer;
use alloy_signer_wallet::LocalWallet;
use alloy_sol_types::{eip712_domain, sol, SolStruct};
use eyre::Result;
use serde::Serialize;

sol! {
Expand All @@ -18,7 +19,7 @@ sol! {
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
async fn main() -> Result<()> {
// Setup up wallet.
let wallet = LocalWallet::random();

Expand Down
3 changes: 2 additions & 1 deletion examples/wallets/examples/trezor_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ use alloy_rpc_client::RpcClient;
use alloy_rpc_types::request::TransactionRequest;
use alloy_signer_trezor::{TrezorHDPath, TrezorSigner};
use alloy_transport_http::Http;
use eyre::Result;
use reqwest::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
async fn main() -> Result<()> {
// Instantiate the application by acquiring a lock on the Trezor device.
let signer = TrezorSigner::new(TrezorHDPath::TrezorLive(0), Some(1)).await?;

Expand Down
3 changes: 2 additions & 1 deletion examples/wallets/examples/yubi_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ use alloy_signer_wallet::{
YubiWallet,
};
use alloy_transport_http::Http;
use eyre::Result;
use reqwest::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
async fn main() -> Result<()> {
// 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 information.
let connector = Connector::usb(&UsbConfig::default());
Expand Down

0 comments on commit f02a16f

Please sign in to comment.