Ethers-rs is a comprehensive library for Ethereum and Celo, written in Rust. It aims to provide a rich set of tools and features to interact with Ethereum-compatible blockchains. Despite its current deprecation in favor of Alloy, it remains a robust resource for Rust developers working with blockchain technology.
Ethers-rs offers a complete suite for Ethereum development, including:
To get started with ethers-rs, add it to your Cargo.toml:
[dependencies]
ethers = "2.0"use ethers::prelude::*;Detailed documentation is available on docs.rs and the online book. Examples can be found in the /examples folder of the repository.
Ethers-rs supports multiple Ethereum-compatible chains. For chains not supporting EIP-2718 Typed Transactions, enable the legacy feature flag:
[dependencies]
ethers = { version = "2.0", features = ["legacy"] }Ethers-rs provides abigen support for Polygon and the Mumbai test network. Set the POLYGONSCAN_API_KEY environment variable to utilize this feature.
For Avalanche and the Fuji test network, ethers-rs includes abigen support. Configure the SNOWTRACE_API_KEY environment variable for optimal functionality.
Enable Optimism support via the optimism feature flag:
[dependencies]
ethers = { version = "2.0", features = ["optimism"] }Optimism introduces new transaction types requiring additional fields:
sourceHashmintisSystemTxEthers-rs supports Celo through the celo feature flag:
[dependencies]
ethers = { version = "2.0", features = ["celo"] }Celo transactions include unique fields:
fee_currencygateway_fee_recipientgateway_feeEthers-rs is equipped with various other functionalities:
ws feature flag.ipc feature flag.rustls and openssl feature flags for secure connections.Enable Websockets support:
[dependencies]
ethers = { version = "2.0", features = ["ws"] }Enable IPC support:
[dependencies]
ethers = { version = "2.0", features = ["ipc"] }For secure connections to HTTPS endpoints, enable either rustls or openssl:
[dependencies]
ethers = { version = "2.0", features = ["rustls"] }[dependencies]
ethers = { version = "2.0", features = ["openssl"] }While ethers-rs can compile to WASM, there are no official plans for a JS/TS-accessible library. If issues arise, users are encouraged to open an issue on GitHub. Similarly, for FFI bindings, ethers-rs can compile to C library formats, but official support is not planned.
Explore the potential of ethers-rs for your Rust-based blockchain applications, leveraging its extensive features and multi-chain support to build and interact with decentralized applications.