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>
👎Deprecated since 0.8.0: pass the transport: use EthereumClient::new_with_http
pub fn new(config: &ChainsConfig) -> Result<Self>
pass the transport: use EthereumClient::new_with_http
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 new_with_http(
config: &ChainsConfig,
http: Arc<dyn HttpClient>,
) -> Result<Self>
pub fn new_with_http( config: &ChainsConfig, http: Arc<dyn HttpClient>, ) -> Result<Self>
Creates a new Ethereum client with an injected HTTP transport.
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>
👎Deprecated since 0.8.0: pass the transport: use EthereumClient::for_chain_with_http
pub fn for_chain(chain: &str, config: &ChainsConfig) -> Result<Self>
pass the transport: use EthereumClient::for_chain_with_http
Creates a client for a specific EVM chain.
§Arguments
chain- Chain identifier (ethereum, polygon, arbitrum, optimism, base, bsc)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 BscScan
§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 for_chain_with_http(
chain: &str,
config: &ChainsConfig,
http: Arc<dyn HttpClient>,
) -> Result<Self>
pub fn for_chain_with_http( chain: &str, config: &ChainsConfig, http: Arc<dyn HttpClient>, ) -> Result<Self>
Creates a chain-specific client with an injected HTTP transport.
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_code(&self, address: &str) -> Result<String>
pub async fn get_code(&self, address: &str) -> Result<String>
Fetches bytecode at address (eth_getCode). Returns “0x” for EOA, non-empty for contracts.
Sourcepub async fn get_storage_at(&self, address: &str, slot: &str) -> Result<String>
pub async fn get_storage_at(&self, address: &str, slot: &str) -> Result<String>
Reads a storage slot value at a contract address (eth_getStorageAt).
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.