usdshe
A Rust crate for conveniently accessing USDC contract addresses on various blockchain networks.
usdshe provides a simple trait, Usdc, which can be implemented for different chain identifiers to retrieve the respective USDC contract address. Currently, it offers an implementation for alloy_chains::NamedChain.
Installation
Add this to your Cargo.toml:
[]
= "0.1.0" # Or the latest version
= "0.2.2" # Or your desired version
= "1.1.2" # Or your desired version
= "1.0" # For error handling if you interact with UsdcError
(Note: Added thiserror to the example dependencies as users might want to match on UsdcError specifically, though it's not strictly required just to use the usdc_address method and handle its Result.)
Usage
use ; // Import UsdcError if you want to match specific errors
use NamedChain;
use Address;
Supported Chains
The Usdc trait is implemented for the following NamedChain variants:
- Arbitrum
- ArbitrumSepolia
- Avalanche
- Base
- BaseSepolia
- BinanceSmartChain (BSC)
- Ethereum (Mainnet)
- EthereumSepolia (Sepolia)
- Fantom
- Fraxtal
- Linea
- Mantle
- Mode
- Optimism
- Polygon
- Scroll
- Sonic
- ZkSync
If you attempt to get the USDC address for an unsupported chain using the NamedChain implementation, the usdc_address method will return an Err(UsdcError::UnsupportedChain(chain_name)). If a known address string fails to parse (which should be rare for correctly defined constants), it will return Err(UsdcError::AddressParseError { .. }).
Contributing
Contributions are welcome! If you'd like to add support for a new chain or improve existing functionality, please feel free to open an issue or submit a pull request.
When adding a new chain, please ensure you:
- Add the USDC contract address constant in the appropriate
src/address/module (either a new file orsrc/address/mod.rs). Ensure it's a valid address string. - Export it with a clear name (e.g.,
CHAIN_NAME_USDC). - Add a match arm for the
NamedChainvariant insrc/lib.rsto returnOk(YOUR_CHAIN_USDC_CONSTANT). - Update this README with the newly supported chain.
License
This crate is licensed under the MIT License.