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

Commit ea4247b

Browse files
committed
avoid using RootProvider directly, use on_client and new_http
1 parent 24dfcfe commit ea4247b

5 files changed

Lines changed: 16 additions & 27 deletions

File tree

‎examples/wallets/Cargo.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ alloy-signer-ledger.workspace = true
2222
alloy-signer-trezor.workspace = true
2323
alloy-signer-wallet = { workspace = true, features = ["mnemonic", "yubihsm"] }
2424
alloy-sol-types.workspace = true
25-
alloy-transport-http.workspace = true
2625

2726
eyre.workspace = true
2827
reqwest.workspace = true

‎examples/wallets/examples/ledger_signer.rs‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,22 @@
22
33
use alloy_network::EthereumSigner;
44
use alloy_primitives::{address, U256};
5-
use alloy_provider::{Provider, ProviderBuilder, RootProvider};
5+
use alloy_provider::{Provider, ProviderBuilder};
66
use alloy_rpc_client::RpcClient;
77
use alloy_rpc_types::request::TransactionRequest;
88
use alloy_signer_ledger::{HDPath, LedgerSigner};
9-
use alloy_transport_http::Http;
109
use eyre::Result;
11-
use reqwest::Client;
1210

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

18-
// Create a provider with the signer and the network.
19-
let http = Http::<Client>::new("http://localhost:8545".parse()?);
20-
21-
// Initialize the provider.
16+
// Create a provider with the signer.
17+
let http = "http://localhost:8545".parse()?;
2218
let provider = ProviderBuilder::new()
2319
.signer(EthereumSigner::from(signer))
24-
.provider(RootProvider::new(RpcClient::new(http, true)));
20+
.on_client(RpcClient::new_http(http));
2521

2622
// Create a transaction.
2723
let tx = TransactionRequest {

‎examples/wallets/examples/private_key_signer.rs‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
use alloy_network::EthereumSigner;
44
use alloy_node_bindings::Anvil;
55
use alloy_primitives::U256;
6-
use alloy_provider::{Provider, ProviderBuilder, RootProvider};
6+
use alloy_provider::{Provider, ProviderBuilder};
77
use alloy_rpc_client::RpcClient;
88
use alloy_rpc_types::request::TransactionRequest;
99
use alloy_signer_wallet::LocalWallet;
10-
use alloy_transport_http::Http;
1110
use eyre::Result;
12-
use reqwest::Client;
1311

1412
#[tokio::main]
1513
async fn main() -> Result<()> {
@@ -20,11 +18,11 @@ async fn main() -> Result<()> {
2018
let alice: LocalWallet = anvil.keys()[0].clone().into();
2119
let bob: LocalWallet = anvil.keys()[1].clone().into();
2220

23-
// Create a provider with a signer and the network.
24-
let http = Http::<Client>::new(anvil.endpoint().parse()?);
21+
// Create a provider with the signer.
22+
let http = "http://localhost:8545".parse()?;
2523
let provider = ProviderBuilder::new()
2624
.signer(EthereumSigner::from(alice))
27-
.provider(RootProvider::new(RpcClient::new(http, true)));
25+
.on_client(RpcClient::new_http(http));
2826

2927
// Create a transaction.
3028
let tx = TransactionRequest {

‎examples/wallets/examples/trezor_signer.rs‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,22 @@
22
33
use alloy_network::EthereumSigner;
44
use alloy_primitives::{address, U256};
5-
use alloy_provider::{Provider, ProviderBuilder, RootProvider};
5+
use alloy_provider::{Provider, ProviderBuilder};
66
use alloy_rpc_client::RpcClient;
77
use alloy_rpc_types::request::TransactionRequest;
88
use alloy_signer_trezor::{TrezorHDPath, TrezorSigner};
9-
use alloy_transport_http::Http;
109
use eyre::Result;
11-
use reqwest::Client;
1210

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

18-
// Create a provider with the signer and the network.
19-
let http = Http::<Client>::new("http://localhost:8545".parse()?);
16+
// Create a provider with the signer.
17+
let http = "http://localhost:8545".parse()?;
2018
let provider = ProviderBuilder::new()
2119
.signer(EthereumSigner::from(signer))
22-
.provider(RootProvider::new(RpcClient::new(http, true)));
20+
.on_client(RpcClient::new_http(http));
2321

2422
// Create a transaction.
2523
let tx = TransactionRequest {

‎examples/wallets/examples/yubi_signer.rs‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
33
use alloy_network::EthereumSigner;
44
use alloy_primitives::{address, U256};
5-
use alloy_provider::{Provider, ProviderBuilder, RootProvider};
5+
use alloy_provider::{Provider, ProviderBuilder};
66
use alloy_rpc_client::RpcClient;
77
use alloy_rpc_types::request::TransactionRequest;
88
use alloy_signer_wallet::{
99
yubihsm::{Connector, Credentials, UsbConfig},
1010
YubiWallet,
1111
};
12-
use alloy_transport_http::Http;
1312
use eyre::Result;
14-
use reqwest::Client;
1513

1614
#[tokio::main]
1715
async fn main() -> Result<()> {
@@ -24,11 +22,11 @@ async fn main() -> Result<()> {
2422
// to generate a new keypair.
2523
let signer = YubiWallet::connect(connector, Credentials::default(), 0);
2624

27-
// Create a provider with the signer and the network.
28-
let http = Http::<Client>::new("http://localhost:8545".parse()?);
25+
// Create a provider with the signer.
26+
let http = "http://localhost:8545".parse()?;
2927
let provider = ProviderBuilder::new()
3028
.signer(EthereumSigner::from(signer))
31-
.provider(RootProvider::new(RpcClient::new(http, true)));
29+
.on_client(RpcClient::new_http(http));
3230

3331
// Create a transaction.
3432
let tx = TransactionRequest {

0 commit comments

Comments
 (0)