Skip to content

Commit

Permalink
update wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
zerosnacks committed Mar 14, 2024
1 parent f6d7945 commit 66bab27
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 15 deletions.
97 changes: 97 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Examples

These examples demonstrate the main features of Alloy and how to use them.
To run an example, use the command `cargo run --example <Example>`.

```sh
cargo run --example mnemonic_signer
```

---

## Table of Contents

- [ ] Address book
- [ ] Anvil
- [ ] Boot anvil
- [ ] Deploy contracts
- [ ] Fork
- [ ] Testing
- [ ] Big numbers
- [ ] Comparison and equivalence
- [ ] Conversion
- [ ] Creating Instances
- [ ] Math operations
- [ ] Utilities
- [ ] Contracts
- [ ] Abigen
- [ ] Compile
- [ ] Creating Instances
- [ ] Deploy Anvil
- [ ] Deploy from ABI and bytecode
- [ ] Deploy Moonbeam
- [ ] Events
- [ ] Events with meta
- [ ] Methods
- [ ] Events
- [ ] Logs and filtering
- [ ] Solidity topics
- [ ] Middleware
- [ ] Builder
- [ ] Create custom middleware
- [ ] Gas escalator
- [ ] Gas oracle
- [ ] Nonce manager
- [ ] Policy
- [ ] Signer
- [ ] Time lag
- [ ] Transformer
- [ ] Providers
- [ ] Http
- [ ] IPC
- [ ] Mock
- [ ] Quorum
- [ ] Retry
- [ ] RW
- [ ] WS
- [ ] Queries
- [ ] Blocks
- [ ] Contracts
- [ ] Events
- [ ] Paginated logs
- [ ] UniswapV2 pair
- [ ] Transactions
- [ ] Subscriptions
- [ ] Watch blocks
- [ ] Subscribe events by type
- [ ] Subscribe logs
- [ ] Transactions
- [ ] Call override
- [ ] Create raw transaction
- [ ] Create typed transaction
- [ ] Decode input
- [ ] EIP-1559
- [ ] ENS
- [ ] Estimate gas
- [ ] Get gas price
- [ ] Get gas price USD
- [ ] Remove liquidity
- [ ] Set gas for a transaction
- [ ] Send raw transaction
- [ ] Send typed transaction
- [ ] Trace
- [ ] Transaction receipt
- [ ] Transaction status
- [ ] Transfer ETH
- [ ] Transfer ERC20 token
- [ ] Wallets
- [ ] AWS signer
- [ ] GCP signer
- [x] [Ledger signer](./wallets/examples/ledger_signer.rs)
- [x] [Private key signer](./wallets/examples/private_key_signer.rs)
- [x] [Mnemonic signer](./wallets/examples/mnemonic_signer.rs)
- [x] [Sign message](./wallets/examples/sign_message.rs)
- [x] [Sign permit hash](./wallets/examples/sign_permit_hash.rs)
- [x] [Trezor signer](./wallets/examples/trezor_signer.rs)
- [x] [Yubi signer](./wallets/examples/yubi_signer.rs)
- [ ] Keystore signer
2 changes: 1 addition & 1 deletion examples/wallets/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[package]
name = "examples-wallets"
publish = false

version.workspace = true
edition.workspace = true
Expand All @@ -9,7 +10,6 @@ license.workspace = true
homepage.workspace = true
repository.workspace = true
exclude.workspace = true
publish.workspace = true

[dev-dependencies]
alloy-network.workspace = true
Expand Down
5 changes: 2 additions & 3 deletions examples/wallets/examples/ledger_signer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Example of signing and sending a transaction using a Ledger device.
use alloy_network::{Ethereum, EthereumSigner};
use alloy_network::EthereumSigner;
use alloy_primitives::{address, U256};
use alloy_provider::{Provider, ProviderBuilder, RootProvider};
use alloy_rpc_client::RpcClient;
Expand All @@ -16,9 +16,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

// Create a provider with the signer and the network.
let http = Http::<Client>::new("http://localhost:8545".parse()?);
let provider = ProviderBuilder::<_, Ethereum>::new()
let provider = ProviderBuilder::new()
.signer(EthereumSigner::from(signer))
.network::<Ethereum>()
.provider(RootProvider::new(RpcClient::new(http, true)));

// Create a transaction.
Expand Down
4 changes: 2 additions & 2 deletions examples/wallets/examples/mnemonic_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.password(password)
.build()?;

println!("Wallet: {:?}", wallet);
println!("Wallet: {:?}", wallet.address());

// Generate a random wallet (24 word phrase) at custom derivation path
let mut rng = rand::thread_rng();
Expand All @@ -31,7 +31,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// .write_to(path)
.build_random(&mut rng)?;

println!("Random wallet: {:?}", wallet);
println!("Random wallet: {:?}", wallet.address());

Ok(())
}
5 changes: 2 additions & 3 deletions examples/wallets/examples/private_key_signer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Example of using a local wallet to sign and broadcast a transaction on a local Anvil node.
use alloy_network::{Ethereum, EthereumSigner};
use alloy_network::EthereumSigner;
use alloy_node_bindings::Anvil;
use alloy_primitives::{U256, U64};
use alloy_provider::{Provider, ProviderBuilder, RootProvider};
Expand All @@ -21,9 +21,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

// Create a provider with a signer and the network.
let http = Http::<Client>::new(anvil.endpoint().parse()?);
let provider = ProviderBuilder::<_, Ethereum>::new()
let provider = ProviderBuilder::new()
.signer(EthereumSigner::from(alice))
.network::<Ethereum>()
.provider(RootProvider::new(RpcClient::new(http, true)));

// Create a transaction.
Expand Down
5 changes: 2 additions & 3 deletions examples/wallets/examples/trezor_signer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Example of signing and sending a transaction using a Trezor device.
use alloy_network::{Ethereum, EthereumSigner};
use alloy_network::EthereumSigner;
use alloy_primitives::{address, U256};
use alloy_provider::{Provider, ProviderBuilder, RootProvider};
use alloy_rpc_client::RpcClient;
Expand All @@ -16,9 +16,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

// Create a provider with the signer and the network.
let http = Http::<Client>::new("http://localhost:8545".parse()?);
let provider = ProviderBuilder::<_, Ethereum>::new()
let provider = ProviderBuilder::new()
.signer(EthereumSigner::from(signer))
.network::<Ethereum>()
.provider(RootProvider::new(RpcClient::new(http, true)));

// Create a transaction.
Expand Down
5 changes: 2 additions & 3 deletions examples/wallets/examples/yubi_signer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Example of signing and sending a transaction using a Yubi device.
use alloy_network::{Ethereum, EthereumSigner};
use alloy_network::EthereumSigner;
use alloy_primitives::{address, U256};
use alloy_provider::{Provider, ProviderBuilder, RootProvider};
use alloy_rpc_client::RpcClient;
Expand All @@ -25,9 +25,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

// Create a provider with the signer and the network.
let http = Http::<Client>::new("http://localhost:8545".parse()?);
let provider = ProviderBuilder::<_, Ethereum>::new()
let provider = ProviderBuilder::new()
.signer(EthereumSigner::from(signer))
.network::<Ethereum>()
.provider(RootProvider::new(RpcClient::new(http, true)));

// Create a transaction.
Expand Down

0 comments on commit 66bab27

Please sign in to comment.