Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion crates/rpc/rpc-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

use crate::{auth::AuthRpcModule, error::WsHttpSamePortError, metrics::RpcRequestMetrics};
use alloy_network::Ethereum;
use alloy_network::{Ethereum, IntoWallet};
use alloy_provider::{fillers::RecommendedFillers, Provider, ProviderBuilder};
use core::marker::PhantomData;
use error::{ConflictingModules, RpcError, ServerKind};
Expand Down Expand Up @@ -2089,6 +2089,21 @@ impl RpcServerHandle {
self.new_http_provider_for()
}

/// Returns a new [`alloy_network::Ethereum`] http provider with its recommended fillers and
/// installed wallet.
pub fn eth_http_provider_with_wallet<W>(
&self,
wallet: W,
) -> Option<impl Provider<alloy_network::Ethereum> + Clone + Unpin + 'static>
where
W: IntoWallet<alloy_network::Ethereum, NetworkWallet: Clone + Unpin + 'static>,
{
let rpc_url = self.http_url()?;
let provider =
ProviderBuilder::new().wallet(wallet).connect_http(rpc_url.parse().expect("valid url"));
Some(provider)
}

/// Returns an http provider from the rpc server handle for the
/// specified [`alloy_network::Network`].
///
Expand All @@ -2111,6 +2126,24 @@ impl RpcServerHandle {
self.new_ws_provider_for().await
}

/// Returns a new [`alloy_network::Ethereum`] ws provider with its recommended fillers and
/// installed wallet.
pub async fn eth_ws_provider_with_wallet<W>(
&self,
wallet: W,
) -> Option<impl Provider<alloy_network::Ethereum> + Clone + Unpin + 'static>
where
W: IntoWallet<alloy_network::Ethereum, NetworkWallet: Clone + Unpin + 'static>,
{
let rpc_url = self.ws_url()?;
let provider = ProviderBuilder::new()
.wallet(wallet)
.connect(&rpc_url)
.await
.expect("failed to create ws client");
Some(provider)
}

/// Returns an ws provider from the rpc server handle for the
/// specified [`alloy_network::Network`].
///
Expand Down