ERC20 is a Rust libary relying on Alloy allowing to interact with ERC-20 contracts.
Add alloy-erc20 to your Cargo.toml.
alloy-erc20 = "1.0"- 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. - A
LazyTokenSignerstruct for executing write operations liketransfer,approve, andtransferFromwith a signer-capable provider.
This library includes comprehensive integration tests using testcontainers-modules and Anvil.
The integration tests:
- Run completely standalone without external RPC dependencies
- Deploy a mock ERC-20 contract to a blank Anvil dev chain
- Test all
LazyTokenandLazyTokenSigneroperations - Complete in approximately 1 second
- Require only Docker to be installed
To run the integration tests:
cargo test --test integration_tests