Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
alloy-erc20-full
Complete ERC20 SDK for Alloy with both read and write operations.
Forked from alloy-erc20 to add write operation support (transfer, approve, transferFrom).
⚠️ DEPRECATED - Use alloy-erc20-full Instead
This crate (erc20-rs) has been superseded
by alloy-erc20-full.
Why the Change?
Research showed that the excellent alloy-erc20
crate already provides superior read-only ERC20
functionality with caching,
BigDecimal support, and TokenStore. However, it
lacks write operations.
alloy-erc20-full is a fork of alloy-erc20
that adds write operation
support while preserving all of its excellent
features.
Migration
See the Migration Guide.
Links:
- New Crate: https://crates.io/crates/alloy-erc20-full
- Repository: https://github.com/suchapalaver/erc20-rs (same repo, different crate)
- Migration Guide: https://github.com/suchapalaver/erc20-rs/blob/main/MIGRATION_FROM_ERC20_RS.md
Why alloy-erc20-full?
| Feature | Raw Alloy sol! |
alloy-erc20 |
alloy-erc20-full |
|---|---|---|---|
| Read Operations | ✅ Manual | ✅ Easy helpers | ✅ Easy helpers + caching |
| Write Operations | ✅ Manual | ❌ Not supported | ✅ Supported |
| Metadata Caching | ❌ | ✅ LazyToken | ✅ LazyToken |
| TokenStore | ❌ | ✅ | ✅ |
| BigDecimal Support | ❌ | ✅ | ✅ |
| Provider Extensions | ❌ | ✅ | ✅ |
Use this crate if you need:
- Complete ERC20 functionality (read + write)
- Convenient helpers with caching
- BigDecimal balance conversion
- Token metadata management
Use alloy-erc20 if you only need:
- Read-only operations
- Token metadata queries
Use raw Alloy if you want:
- Maximum control
- Minimal dependencies
Installation
Add to your Cargo.toml:
[]
= "1.0"
= { = "1.0", = ["full"] }
Quick Start
Read Operations (Query Token Data)
use ;
use ProviderBuilder;
use LazyToken;
async
Write Operations (Transfer, Approve)
Important: Provider must be configured with a signer/wallet for write operations.
use EthereumWallet;
use ;
use ProviderBuilder;
use PrivateKeySigner;
use LazyToken;
async
Features
LazyToken - Cached Token Instance
use LazyToken;
// Metadata (name, symbol, decimals) is cached after first query
let token = new;
// First call queries the network
let symbol = token.symbol.await?; // Network call
// Subsequent calls use cache
let symbol_again = token.symbol.await?; // From cache!
// Always queries network (not cached)
let balance = token.balance_of.await?;
let supply = token.total_supply.await?;
Provider Extensions
use Erc20ProviderExt;
// Any Alloy provider automatically gets ERC20 methods
let token_info = provider.retrieve_token.await?;
println!;
// Get balance as BigDecimal
let balance = provider.balance_of.await?;
TokenStore - Multi-Chain Token Registry
use ;
let mut store = new;
// Retrieve and cache token
let dai = provider.get_token.await?;
// Later, retrieve from store by symbol or address
let dai_from_store = store.get;
Architecture
This crate is a fork of alloy-erc20 with the following additions:
- Public
instancefield onLazyToken- Provides direct access to the underlying Alloy contract for write operations - Complete ERC20 support - All standard ERC20 methods (read + write)
- Maintained compatibility - All original
alloy-erc20features work identically
Core Types
LazyToken<P, N>- Token instance with lazy-loaded metadata cachingToken- Simple struct with address, symbol, decimalsErc20ProviderExt- Trait extending Alloy providers with ERC20 helpersTokenStore- Trait for caching tokens (withBasicTokenStoreandLruTokenStoreimpls)
Migration Guides
From erc20-rs 0.2.x
See MIGRATION_FROM_ERC20_RS.md for detailed guide.
Quick comparison:
// OLD: erc20-rs 0.2.x
use Erc20;
let erc20 = new;
let balance = erc20.balance_of.await?;
let tx = erc20.transfer.await?;
// NEW: alloy-erc20-full 1.0
use LazyToken;
let token = new;
let balance = token.balance_of.await?;
let receipt = token.instance.transfer.send.await?.watch.await?;
From alloy-erc20
alloy-erc20-full is a superset of alloy-erc20. All code using alloy-erc20 works identically:
// Just change the crate name in Cargo.toml
// alloy-erc20 = "1.0" ← old
alloy-erc20-full = "1.0" // ← new
// And update imports
// use alloy_erc20::LazyToken; ← old
use LazyToken; // ← new
// All existing code works as-is!
New capability: Write operations via .instance field.
Examples
See examples/ directory:
lazy.rs- LazyToken with cachingprovider_ext.rs- Provider extension methodsbasic_store.rs- TokenStore usage
Run with:
ETH_MAINNET_RPC=https://eth.llamarpc.com
Features
Default
- Basic functionality with
BasicTokenStore
Optional
lru-store- AddsLruTokenStorewith LRU eviction policyknown-tokens- Pre-populated token lists for mainnet and Arbitrum
[]
= { = "1.0", = ["lru-store", "known-tokens"] }
Testing
Minimum Supported Rust Version (MSRV)
Rust 1.75+
License
Licensed under Apache-2.0 OR MIT (to respect both original erc20-rs and alloy-erc20 licenses).
Attribution
This crate is a fork of alloy-erc20 by @leruaa, extended to support write operations.
Contributing
Contributions welcome! This crate aims to eventually contribute write operation support back to the upstream alloy-erc20 project.
Changelog
1.0.0 (2025-11)
- Forked from
alloy-erc201.0.0 - Added write operation support by exposing contract
instancefield - Complete ERC20 functionality (read + write)
- Maintained full compatibility with
alloy-erc20API