ERC20
ERC20 is a Rust libary relying on Alloy allowing to interact with ERC-20 contracts.
Installation
Add erc20-rs to your Cargo.toml.
= { = "https://github.com/leruaa/erc20-rs" }
Features
- A basic
Tokenstruct and associated extensions methods on Alloy'sProvider, allowing to retrieve token decimals, and compute balances asBigDecimalfromU256. - A
TokenStoretrait, and aBasicTokenStoreimpl, allowing to cacheTokens in memory. - A
LazyTokenstruct, acting as a wrapper around Alloy contract instance, lazily retrievingname,symbol,decimalsandtotalSupplyfrom the blockchain.
Getting started
let provider = new.on_http;
// Just retrieve a token from its address
let dai = provider
.retrieve_token
.await?;
// Compute a balance as a BigDecimal from a U256
let balance = dai.get_balance;