pub struct Erc20Contract { /* private fields */ }Expand description
Interface for interacting with ERC20 token contracts on a blockchain.
This struct provides methods to fetch token metadata (name, symbol, decimals). From ERC20-compliant tokens on any EVM-compatible blockchain.
Implementations§
Source§impl Erc20Contract
impl Erc20Contract
Sourcepub fn new(
client: Arc<BlockchainHttpRpcClient>,
enforce_token_fields: bool,
) -> Self
pub fn new( client: Arc<BlockchainHttpRpcClient>, enforce_token_fields: bool, ) -> Self
Creates a new ERC20 contract interface with the specified RPC client.
Sourcepub async fn fetch_token_info(
&self,
token_address: &Address,
) -> Result<TokenInfo, TokenInfoError>
pub async fn fetch_token_info( &self, token_address: &Address, ) -> Result<TokenInfo, TokenInfoError>
Fetches complete token information (name, symbol, decimals) from an ERC20 contract.
§Errors
Returns an error if any of the contract calls fail.
BlockchainRpcClientError::ClientErrorif an RPC call fails.BlockchainRpcClientError::AbiDecodingErrorif ABI decoding fails.
Sourcepub async fn batch_fetch_token_info(
&self,
token_addresses: &[Address],
) -> Result<HashMap<Address, Result<TokenInfo, TokenInfoError>>, BlockchainRpcClientError>
pub async fn batch_fetch_token_info( &self, token_addresses: &[Address], ) -> Result<HashMap<Address, Result<TokenInfo, TokenInfoError>>, BlockchainRpcClientError>
Fetches token information for multiple tokens in a single multicall.
If the multicall fails (typically due to expired/broken contracts causing RPC “out of gas”), automatically falls back to individual token fetches to isolate problematic contracts.
§Errors
Returns an error only if the operation cannot proceed. Multicall failures trigger
automatic fallback to individual fetches. Individual token failures are captured
in the Result values of the returned HashMap.
Sourcepub async fn balance_of(
&self,
token_address: &Address,
account: &Address,
) -> Result<U256, BlockchainRpcClientError>
pub async fn balance_of( &self, token_address: &Address, account: &Address, ) -> Result<U256, BlockchainRpcClientError>
Fetches the balance of a specific account for this ERC20 token.
§Errors
Returns an error if the contract call fails.
BlockchainRpcClientError::ClientErrorif an RPC call fails.BlockchainRpcClientError::AbiDecodingErrorif ABI decoding fails.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Erc20Contract
impl !RefUnwindSafe for Erc20Contract
impl Send for Erc20Contract
impl Sync for Erc20Contract
impl Unpin for Erc20Contract
impl !UnwindSafe for Erc20Contract
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<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