pub struct EthereumClient { /* private fields */ }Expand description
Ethereum and EVM-compatible chain client.
Uses block explorer APIs (Etherscan, etc.) or JSON-RPC for data retrieval. Supports multiple networks through configuration.
Implementations§
Source§impl EthereumClient
impl EthereumClient
Sourcepub fn new(config: &ChainsConfig) -> Result<Self>
pub fn new(config: &ChainsConfig) -> Result<Self>
Creates a new Ethereum client with the given configuration.
§Arguments
config- Chain configuration containing API keys and endpoints
§Returns
Returns a configured EthereumClient instance.
§Examples
use scope::chains::EthereumClient;
use scope::config::ChainsConfig;
let config = ChainsConfig::default();
let client = EthereumClient::new(&config).unwrap();Sourcepub fn with_base_url(base_url: &str) -> Self
pub fn with_base_url(base_url: &str) -> Self
Creates a client with a custom base URL (for testing or alternative networks).
§Arguments
base_url- The base URL for the block explorer API
Sourcepub fn for_chain(chain: &str, config: &ChainsConfig) -> Result<Self>
pub fn for_chain(chain: &str, config: &ChainsConfig) -> Result<Self>
Creates a client for a specific EVM chain.
§Arguments
chain- Chain identifier (ethereum, polygon, arbitrum, optimism, base, bsc, aegis)config- Chain configuration
§Supported Chains
ethereum- Ethereum mainnet via Etherscanpolygon- Polygon via PolygonScanarbitrum- Arbitrum One via Arbiscanoptimism- Optimism via Etherscanbase- Base via Basescanbsc- BNB Smart Chain (BSC) via BscScanaegis- Aegis/Wraith chain (EVM-compatible, uses JSON-RPC directly)
§API Version
Uses Etherscan V2 API format which requires an API key for most endpoints. Get a free API key at https://etherscan.io/apis
Sourcepub fn chain_name(&self) -> &str
pub fn chain_name(&self) -> &str
Returns the chain name.
Sourcepub fn native_token_symbol(&self) -> &str
pub fn native_token_symbol(&self) -> &str
Returns the native token symbol.
Sourcepub async fn get_balance(&self, address: &str) -> Result<Balance>
pub async fn get_balance(&self, address: &str) -> Result<Balance>
Fetches the native token balance for an address.
§Arguments
address- The Ethereum address to query
§Returns
Returns a Balance struct with the balance in multiple formats.
§Errors
Returns ScopeError::InvalidAddress if the address format is invalid.
Returns ScopeError::Request if the API request fails.
Sourcepub async fn enrich_balance_usd(&self, balance: &mut Balance)
pub async fn enrich_balance_usd(&self, balance: &mut Balance)
Enriches a balance with a USD value using DexScreener price lookup.
Sourcepub async fn get_transaction(&self, hash: &str) -> Result<Transaction>
pub async fn get_transaction(&self, hash: &str) -> Result<Transaction>
Fetches transaction details by hash.
§Arguments
hash- The transaction hash
§Returns
Returns Transaction details.
Sourcepub async fn get_transactions(
&self,
address: &str,
limit: u32,
) -> Result<Vec<Transaction>>
pub async fn get_transactions( &self, address: &str, limit: u32, ) -> Result<Vec<Transaction>>
Fetches recent transactions for an address.
§Arguments
address- The address to querylimit- Maximum number of transactions
§Returns
Returns a vector of Transaction objects.
Sourcepub async fn get_block_number(&self) -> Result<u64>
pub async fn get_block_number(&self) -> Result<u64>
Fetches the current block number.
Sourcepub async fn get_erc20_balances(
&self,
address: &str,
) -> Result<Vec<TokenBalance>>
pub async fn get_erc20_balances( &self, address: &str, ) -> Result<Vec<TokenBalance>>
Fetches ERC-20 token balances for an address.
Uses Etherscan’s tokentx endpoint to find unique tokens the address has interacted with, then fetches current balances for each.
Sourcepub async fn get_token_info(&self, token_address: &str) -> Result<Token>
pub async fn get_token_info(&self, token_address: &str) -> Result<Token>
Sourcepub async fn get_token_holders(
&self,
token_address: &str,
limit: u32,
) -> Result<Vec<TokenHolder>>
pub async fn get_token_holders( &self, token_address: &str, limit: u32, ) -> Result<Vec<TokenHolder>>
Fetches the top token holders for a given token.
§Arguments
token_address- The token contract addresslimit- Maximum number of holders to return (max 1000 for most APIs)
§Returns
Returns a vector of TokenHolder objects sorted by balance.
§Note
This requires an Etherscan Pro API key for most networks.
Sourcepub async fn get_token_holder_count(&self, token_address: &str) -> Result<u64>
pub async fn get_token_holder_count(&self, token_address: &str) -> Result<u64>
Gets the total holder count for a token.
Uses Etherscan token holder list endpoint to estimate the count. If the API returns a full page at the max limit, the count is approximate.
Trait Implementations§
Source§impl ChainClient for EthereumClient
impl ChainClient for EthereumClient
Source§fn chain_name(&self) -> &str
fn chain_name(&self) -> &str
Source§fn native_token_symbol(&self) -> &str
fn native_token_symbol(&self) -> &str
Source§fn get_balance<'life0, 'life1, 'async_trait>(
&'life0 self,
address: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Balance>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_balance<'life0, 'life1, 'async_trait>(
&'life0 self,
address: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Balance>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn enrich_balance_usd<'life0, 'life1, 'async_trait>(
&'life0 self,
balance: &'life1 mut Balance,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn enrich_balance_usd<'life0, 'life1, 'async_trait>(
&'life0 self,
balance: &'life1 mut Balance,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn get_transaction<'life0, 'life1, 'async_trait>(
&'life0 self,
hash: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Transaction>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_transaction<'life0, 'life1, 'async_trait>(
&'life0 self,
hash: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Transaction>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn get_transactions<'life0, 'life1, 'async_trait>(
&'life0 self,
address: &'life1 str,
limit: u32,
) -> Pin<Box<dyn Future<Output = Result<Vec<Transaction>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_transactions<'life0, 'life1, 'async_trait>(
&'life0 self,
address: &'life1 str,
limit: u32,
) -> Pin<Box<dyn Future<Output = Result<Vec<Transaction>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn get_block_number<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_block_number<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn get_token_balances<'life0, 'life1, 'async_trait>(
&'life0 self,
address: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<TokenBalance>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_token_balances<'life0, 'life1, 'async_trait>(
&'life0 self,
address: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<TokenBalance>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn get_token_info<'life0, 'life1, 'async_trait>(
&'life0 self,
address: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Token>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_token_info<'life0, 'life1, 'async_trait>(
&'life0 self,
address: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Token>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn get_token_holders<'life0, 'life1, 'async_trait>(
&'life0 self,
address: &'life1 str,
limit: u32,
) -> Pin<Box<dyn Future<Output = Result<Vec<TokenHolder>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_token_holders<'life0, 'life1, 'async_trait>(
&'life0 self,
address: &'life1 str,
limit: u32,
) -> Pin<Box<dyn Future<Output = Result<Vec<TokenHolder>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn get_token_holder_count<'life0, 'life1, 'async_trait>(
&'life0 self,
address: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_token_holder_count<'life0, 'life1, 'async_trait>(
&'life0 self,
address: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§impl Clone for EthereumClient
impl Clone for EthereumClient
Source§fn clone(&self) -> EthereumClient
fn clone(&self) -> EthereumClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EthereumClient
impl Debug for EthereumClient
Auto Trait Implementations§
impl Freeze for EthereumClient
impl !RefUnwindSafe for EthereumClient
impl Send for EthereumClient
impl Sync for EthereumClient
impl Unpin for EthereumClient
impl !UnwindSafe for EthereumClient
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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