Sitelet https://github.com/SharkHand3/examples/commit/f02a16fe9bc337c66b27dd91086df3fd6d538442
Skip to content

Commit f02a16f

Browse files
committed
add eyre and update wallet examples
1 parent 5eaa6ab commit f02a16f

8 files changed

Lines changed: 18 additions & 9 deletions

File tree

‎examples/wallets/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ alloy-signer-wallet = { workspace = true, features = ["mnemonic", "yubihsm"] }
2424
alloy-sol-types.workspace = true
2525
alloy-transport-http.workspace = true
2626

27-
rand.workspace = true
27+
eyre.workspace = true
2828
reqwest.workspace = true
2929
serde.workspace = true
3030
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }

‎examples/wallets/examples/ledger_signer.rs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ use alloy_rpc_client::RpcClient;
77
use alloy_rpc_types::request::TransactionRequest;
88
use alloy_signer_ledger::{HDPath, LedgerSigner};
99
use alloy_transport_http::Http;
10+
use eyre::Result;
1011
use reqwest::Client;
1112

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

1718
// Create a provider with the signer and the network.
1819
let http = Http::<Client>::new("http://localhost:8545".parse()?);
20+
21+
// Initialize the provider.
1922
let provider = ProviderBuilder::new()
2023
.signer(EthereumSigner::from(signer))
2124
.provider(RootProvider::new(RpcClient::new(http, true)));
@@ -32,7 +35,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
3235
// Broadcast the transaction and wait for the receipt.
3336
let receipt = provider.send_transaction(tx).await?.with_confirmations(3).get_receipt().await?;
3437

35-
println!("Send transaction: {:?}", receipt.transaction_hash.unwrap());
38+
println!("Send transaction: {:?}", receipt.transaction_hash.unwrap_or_default());
3639

3740
Ok(())
3841
}

‎examples/wallets/examples/mnemonic_signer.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
//! Example of using `MnemonicBuilder` to access a wallet from a mnemonic phrase.
22
33
use alloy_signer_wallet::{coins_bip39::English, MnemonicBuilder};
4+
use eyre::Result;
45

56
#[tokio::main]
6-
async fn main() -> Result<(), Box<dyn std::error::Error>> {
7+
async fn main() -> Result<()> {
78
let phrase = "work man father plunge mystery proud hollow address reunion sauce theory bonus";
89
let index = 0u32;
910
let password = "TREZOR123";

‎examples/wallets/examples/private_key_signer.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ use alloy_rpc_client::RpcClient;
88
use alloy_rpc_types::request::TransactionRequest;
99
use alloy_signer_wallet::LocalWallet;
1010
use alloy_transport_http::Http;
11+
use eyre::Result;
1112
use reqwest::Client;
1213

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

‎examples/wallets/examples/sign_message.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
33
use alloy_signer::Signer;
44
use alloy_signer_wallet::LocalWallet;
5+
use eyre::Result;
56

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

‎examples/wallets/examples/sign_permit_hash.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use alloy_primitives::{address, keccak256, U256};
44
use alloy_signer::Signer;
55
use alloy_signer_wallet::LocalWallet;
66
use alloy_sol_types::{eip712_domain, sol, SolStruct};
7+
use eyre::Result;
78
use serde::Serialize;
89

910
sol! {
@@ -18,7 +19,7 @@ sol! {
1819
}
1920

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

‎examples/wallets/examples/trezor_signer.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ use alloy_rpc_client::RpcClient;
77
use alloy_rpc_types::request::TransactionRequest;
88
use alloy_signer_trezor::{TrezorHDPath, TrezorSigner};
99
use alloy_transport_http::Http;
10+
use eyre::Result;
1011
use reqwest::Client;
1112

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

‎examples/wallets/examples/yubi_signer.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ use alloy_signer_wallet::{
1010
YubiWallet,
1111
};
1212
use alloy_transport_http::Http;
13+
use eyre::Result;
1314
use reqwest::Client;
1415

1516
#[tokio::main]
16-
async fn main() -> Result<(), Box<dyn std::error::Error>> {
17+
async fn main() -> Result<()> {
1718
// We use USB for the example, but you can connect over HTTP as well. Refer
1819
// to the [YubiHSM](https://docs.rs/yubihsm/0.34.0/yubihsm/) docs for more information.
1920
let connector = Connector::usb(&UsbConfig::default());

0 commit comments

Comments
 (0)