alloy_provider/ext/rpc.rs
1//! This module extends the Ethereum JSON-RPC provider with the Rpc namespace's RPC methods.
2use crate::Provider;
3use alloy_network::Network;
4use alloy_rpc_types::RpcModules;
5use alloy_transport::TransportResult;
6
7/// The rpc API provides methods to get information about the RPC server itself, such as the enabled
8/// namespaces.
9#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
10#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
11pub trait RpcApi<N>: Send + Sync {
12 /// Lists the enabled RPC namespaces and the versions of each.
13 async fn rpc_modules(&self) -> TransportResult<RpcModules>;
14}
15
16#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
17#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
18impl<N, P> RpcApi<N> for P
19where
20 N: Network,
21 P: Provider<N>,
22{
23 async fn rpc_modules(&self) -> TransportResult<RpcModules> {
24 self.client().request_noparams("rpc_modules").await
25 }
26}