pub struct BlockchainHttpRpcClient { /* private fields */ }Expand description
Client for making HTTP-based RPC requests to blockchain nodes.
This client is designed to interact with Ethereum-compatible blockchain networks, providing methods to execute RPC calls and handle responses in a type-safe manner.
Implementations§
Source§impl BlockchainHttpRpcClient
impl BlockchainHttpRpcClient
Sourcepub fn new(http_rpc_url: String, rpc_request_per_second: Option<u32>) -> Self
pub fn new(http_rpc_url: String, rpc_request_per_second: Option<u32>) -> Self
Creates a new HTTP RPC client with the given endpoint URL and optional rate limit.
§Panics
Panics if rpc_request_per_second is Some(0), since a zero rate limit is invalid.
Sourcepub async fn execute_rpc_call<T: DeserializeOwned>(
&self,
rpc_request: Value,
) -> Result<T>
pub async fn execute_rpc_call<T: DeserializeOwned>( &self, rpc_request: Value, ) -> Result<T>
Executes an Ethereum JSON-RPC call and deserializes the response into the specified type T.
§Errors
Returns an error if the HTTP RPC request fails or the response cannot be parsed.
Sourcepub fn construct_eth_call(
&self,
to: &str,
call_data: &[u8],
block: Option<u64>,
) -> Value
pub fn construct_eth_call( &self, to: &str, call_data: &[u8], block: Option<u64>, ) -> Value
Creates a properly formatted eth_call JSON-RPC request object targeting a specific contract address with encoded function data.
Sourcepub async fn get_balance(
&self,
address: &Address,
block: Option<u64>,
) -> Result<U256>
pub async fn get_balance( &self, address: &Address, block: Option<u64>, ) -> Result<U256>
Retrieves the balance of the specified Ethereum address at the given block.
§Errors
Returns an error if the RPC call fails or if the returned balance string cannot be parsed as a valid U256.
Sourcepub async fn get_logs(
&self,
address: Option<&Address>,
topics: Option<Vec<Option<String>>>,
from_block: u64,
to_block: u64,
) -> Result<Vec<RpcLog>>
pub async fn get_logs( &self, address: Option<&Address>, topics: Option<Vec<Option<String>>>, from_block: u64, to_block: u64, ) -> Result<Vec<RpcLog>>
Retrieves logs matching the given filter criteria.
This method calls the eth_getLogs RPC method to fetch event logs from the blockchain.
It’s commonly used for querying historical events like token transfers, swaps, etc.
§Errors
Returns an error if the RPC call fails or the response cannot be parsed.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BlockchainHttpRpcClient
impl !RefUnwindSafe for BlockchainHttpRpcClient
impl Send for BlockchainHttpRpcClient
impl Sync for BlockchainHttpRpcClient
impl Unpin for BlockchainHttpRpcClient
impl !UnwindSafe for BlockchainHttpRpcClient
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more