Skip to content

Commit

Permalink
avoid using RootProvider directly, use on_client and new_http
Browse files Browse the repository at this point in the history
  • Loading branch information
zerosnacks committed Mar 19, 2024
1 parent 7cdd8e0 commit 35b3a2f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
10 changes: 4 additions & 6 deletions examples/layers/examples/nonce_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
use alloy_network::EthereumSigner;
use alloy_node_bindings::Anvil;
use alloy_primitives::{address, U256};
use alloy_provider::{layers::ManagedNonceLayer, Provider, ProviderBuilder, RootProvider};
use alloy_provider::{layers::ManagedNonceLayer, Provider, ProviderBuilder};
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;

/// In Ethereum, the nonce of a transaction is a number that represents the number of transactions
/// that have been sent from a particular account. The nonce is used to ensure that transactions are
Expand All @@ -30,12 +28,12 @@ async fn main() -> Result<()> {
let wallet: LocalWallet = anvil.keys()[0].clone().into();
let from = wallet.address();

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

let tx = TransactionRequest {
from: Some(from),
Expand Down
10 changes: 4 additions & 6 deletions examples/layers/examples/signer_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
use alloy_network::EthereumSigner;
use alloy_node_bindings::Anvil;
use alloy_primitives::{address, b256, U256};
use alloy_provider::{Provider, ProviderBuilder, RootProvider};
use alloy_provider::{Provider, ProviderBuilder};
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<()> {
Expand All @@ -20,12 +18,12 @@ async fn main() -> Result<()> {
// Set up the wallets.
let wallet: LocalWallet = anvil.keys()[0].clone().into();

// Create a provider with a signer and the network.
let http = Http::<Client>::new(anvil.endpoint().parse()?);
// Create a provider with the signer.
let http = anvil.endpoint().parse()?;
let provider = ProviderBuilder::new()
// Add the `SignerLayer` to the provider
.signer(EthereumSigner::from(wallet))
.provider(RootProvider::new(RpcClient::new(http, true)));
.on_client(RpcClient::new_http(http));

let tx = TransactionRequest {
nonce: Some(0),
Expand Down

0 comments on commit 35b3a2f

Please sign in to comment.