Skip to main content

Module chains

Module chains 

Source
Expand description

Blockchain client implementations.

Provides abstractions and concrete clients for interacting with blockchain networks. See ChainClient for the common interface and EthereumClient for EVM chain support.

§Blockchain Client Module

This module provides abstractions and implementations for interacting with various blockchain networks. It defines a common ChainClient trait that all chain-specific implementations must satisfy.

§Capabilities

All chain clients support:

  • Balance queries with optional USD valuation via DexScreener
  • Transaction lookup by hash/signature with full details
  • Transaction history for addresses with pagination
  • Token balances (ERC-20, SPL, TRC-20) for address book tracking

§Supported Chains

§EVM-Compatible Chains

  • Ethereum - Ethereum Mainnet (via Etherscan V2 API)
  • Polygon - Polygon PoS
  • Arbitrum - Arbitrum One
  • Optimism - Optimism Mainnet
  • Base - Base (Coinbase L2)
  • BSC - BNB Smart Chain (Binance)

§Non-EVM Chains

  • Solana - Solana Mainnet (JSON-RPC with jsonParsed encoding)
  • Tron - Tron Mainnet (TronGrid API, base58check address validation)

§DEX Data

  • DexScreener - Token prices, volume, liquidity, and trading data across all DEX pairs

§Usage

§Ethereum/EVM Client

use scope::chains::{ChainClient, EthereumClient};
use scope::Config;

#[tokio::main]
async fn main() -> scope::Result<()> {
    let config = Config::load(None)?;
    let client = EthereumClient::new(&config.chains)?;
     
    let balance = client.get_balance("0x742d35Cc6634C0532925a3b844Bc9e7595f1b3c2").await?;
    println!("Balance: {} ETH", balance.formatted);
    Ok(())
}

§Solana Client

use scope::chains::SolanaClient;
use scope::Config;

#[tokio::main]
async fn main() -> scope::Result<()> {
    let config = Config::load(None)?;
    let client = SolanaClient::new(&config.chains)?;
     
    let balance = client.get_balance("DRpbCBMxVnDK7maPM5tGv6MvB3v1sRMC86PZ8okm21hy").await?;
    println!("Balance: {} SOL", balance.formatted);
    Ok(())
}

§Tron Client

use scope::chains::TronClient;
use scope::Config;

#[tokio::main]
async fn main() -> scope::Result<()> {
    let config = Config::load(None)?;
    let client = TronClient::new(&config.chains)?;
     
    let balance = client.get_balance("TDqSquXBgUCLYvYC4XZgrprLK589dkhSCf").await?;
    println!("Balance: {} TRX", balance.formatted);
    Ok(())
}

Re-exports§

pub use dex::DexClient;
pub use dex::DexDataSource;
pub use dex::DiscoverToken;
pub use dex::TokenSearchResult;
pub use ethereum::ApiType;
pub use ethereum::EthereumClient;
pub use solana::SolanaClient;
pub use solana::validate_solana_address;
pub use solana::validate_solana_signature;
pub use tron::TronClient;
pub use tron::validate_tron_address;
pub use tron::validate_tron_tx_hash;

Modules§

dex
DEX Aggregator Client
ethereum
Ethereum Client
solana
Solana Client
tron
Tron Client

Structs§

Balance
Balance representation with multiple formats.
ChainMetadata
Metadata for a blockchain network (symbol, decimals, explorer URLs).
DefaultClientFactory
Default factory that creates real chain clients from configuration.
DexPair
DEX trading pair information.
HolderCountPoint
A holder count data point for historical charting.
PricePoint
A price data point for historical charting.
Token
Token information.
TokenAnalytics
Comprehensive token analytics data.
TokenBalance
Token balance for an address.
TokenHolder
A token holder with their balance and percentage of supply.
TokenSocial
Social media link for a token.
Transaction
Transaction information.
VolumePoint
A volume data point for historical charting.

Traits§

ChainClient
Trait defining common blockchain client operations.
ChainClientFactory
Factory trait for creating chain clients and DEX data sources.

Functions§

chain_metadata
Returns chain metadata for display and formatting.
infer_chain_from_address
Infers the blockchain from an address format.
infer_chain_from_hash
Infers the blockchain from a transaction hash format.
native_symbol
Returns the native token symbol for a chain, or “???” if unknown.