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>,
proxy_url: Option<String>,
) -> Self
pub fn new( http_rpc_url: String, rpc_request_per_second: Option<u32>, proxy_url: Option<String>, ) -> Self
Creates a new HTTP RPC client with the given endpoint URL and optional rate limit.
If rpc_request_per_second is Some(0) or an invalid value, rate limiting is disabled.
§Panics
Panics if the internal HTTP client cannot be created.
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 async fn execute_rpc_call_with_timeout<T: DeserializeOwned>(
&self,
rpc_request: Value,
timeout_secs: Option<u64>,
) -> Result<T>
pub async fn execute_rpc_call_with_timeout<T: DeserializeOwned>( &self, rpc_request: Value, timeout_secs: Option<u64>, ) -> Result<T>
Executes an Ethereum JSON-RPC call with an optional per-request timeout 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_balance_with_timeout(
&self,
address: &Address,
block: Option<u64>,
timeout_secs: Option<u64>,
) -> Result<U256>
pub async fn get_balance_with_timeout( &self, address: &Address, block: Option<u64>, timeout_secs: Option<u64>, ) -> Result<U256>
Retrieves the balance of the specified Ethereum address at the given block with an optional per-request timeout.
§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.
Sourcepub async fn chain_id(&self) -> Result<u64>
pub async fn chain_id(&self) -> Result<u64>
Returns the chain ID reported by the RPC node via eth_chainId.
§Errors
Returns an error if the RPC call fails or the result is missing or malformed.
Sourcepub async fn get_code(&self, address: &Address) -> Result<Bytes>
pub async fn get_code(&self, address: &Address) -> Result<Bytes>
Returns the deployed bytecode at the given address via eth_getCode at the latest block.
An address with no deployed contract returns empty bytes.
§Errors
Returns an error if the RPC call fails or the result is missing or malformed.
Sourcepub async fn get_transaction_count_pending(
&self,
address: &Address,
) -> Result<u64>
pub async fn get_transaction_count_pending( &self, address: &Address, ) -> Result<u64>
Returns the next nonce for the given address via eth_getTransactionCount
with the pending tag, making the pending pool state authoritative.
§Errors
Returns an error if the RPC call fails or the result is missing or malformed.
Sourcepub async fn get_transaction_count_latest(
&self,
address: &Address,
) -> Result<u64>
pub async fn get_transaction_count_latest( &self, address: &Address, ) -> Result<u64>
Returns the latest mined nonce for an address.
§Errors
Returns an error if the RPC call fails or the result is missing or malformed.
Sourcepub async fn estimate_gas(
&self,
from: &Address,
to: &Address,
value: U256,
data: &[u8],
) -> Result<u64>
pub async fn estimate_gas( &self, from: &Address, to: &Address, value: U256, data: &[u8], ) -> Result<u64>
Estimates the gas required for a transaction via eth_estimateGas.
§Errors
Returns an error if the RPC call fails (including node-side revert of the simulated transaction) or the result is missing or malformed.
Sourcepub async fn max_priority_fee_per_gas(&self) -> Result<u128>
pub async fn max_priority_fee_per_gas(&self) -> Result<u128>
Returns the node’s suggested max priority fee per gas in wei
via eth_maxPriorityFeePerGas.
§Errors
Returns an error if the RPC call fails or the result is missing or malformed.
Sourcepub async fn latest_block(&self) -> Result<RpcBlock>
pub async fn latest_block(&self) -> Result<RpcBlock>
Returns the latest block via eth_getBlockByNumber with the latest tag.
§Errors
Returns an error if the RPC call fails or the result is missing or malformed.
Sourcepub async fn finalized_block(&self) -> Result<RpcBlock>
pub async fn finalized_block(&self) -> Result<RpcBlock>
Returns the consensus finalized block.
§Errors
Returns an error if the endpoint does not support the finalized tag, the RPC call
fails, or the result is missing or malformed.
Sourcepub async fn block_by_number(
&self,
number: u64,
full_transactions: bool,
) -> Result<RpcBlock>
pub async fn block_by_number( &self, number: u64, full_transactions: bool, ) -> Result<RpcBlock>
Returns a numbered canonical block, optionally with full transactions.
§Errors
Returns an error if the RPC call fails or the result is missing or malformed.
Sourcepub async fn get_transaction_receipt(
&self,
tx_hash: &B256,
) -> Result<Option<RpcTransactionReceipt>>
pub async fn get_transaction_receipt( &self, tx_hash: &B256, ) -> Result<Option<RpcTransactionReceipt>>
Returns the receipt for the given transaction hash via eth_getTransactionReceipt.
A null result maps to Ok(None): the transaction is pending and no receipt
exists yet.
§Errors
Returns an error if the RPC call fails or the response is malformed.
Sourcepub async fn send_raw_transaction(
&self,
raw_tx: &[u8],
expected_tx_hash: &B256,
) -> Result<B256, BroadcastError>
pub async fn send_raw_transaction( &self, raw_tx: &[u8], expected_tx_hash: &B256, ) -> Result<B256, BroadcastError>
Broadcasts a signed raw transaction via eth_sendRawTransaction.
Broadcast failures classify before retry: an already known response is acceptance
(returns expected_tx_hash), and a timeout after sending is
BroadcastError::TimeoutAfterSend so the caller reconciles through the persisted
record rather than rebroadcasting.
§Errors
Returns a BroadcastError classifying the failure. Errors are sanitized: they carry
the numeric RPC code only, never the endpoint URL or the signed payload.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for BlockchainHttpRpcClient
impl !UnwindSafe for BlockchainHttpRpcClient
impl Freeze for BlockchainHttpRpcClient
impl Send for BlockchainHttpRpcClient
impl Sync for BlockchainHttpRpcClient
impl Unpin for BlockchainHttpRpcClient
impl UnsafeUnpin for BlockchainHttpRpcClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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