ethers-rs

Ethers-rs

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.

Overview

Ethers-rs offers a complete suite for Ethereum development, including:

  • Ethereum JSON-RPC Client: Allows easy interaction with Ethereum nodes.
  • Smart Contract Interaction: Supports deploying, calling, and interacting with smart contracts.
  • Type-safe Bindings: Generates safe bindings for smart contracts, ensuring type safety in Rust.
  • Event Handling: Facilitates querying past events and monitoring them as Streams.
  • First-class ENS Support: Integrates seamlessly with the Ethereum Name Service (ENS).
  • Multi-chain Support: Extends functionality to multiple chains, including Celo, Polygon, Avalanche, and Optimism.

Getting Started

To get started with ethers-rs, add it to your Cargo.toml:

[dependencies]
ethers = "2.0"
use ethers::prelude::*;

Documentation

Detailed documentation is available on docs.rs and the online book. Examples can be found in the /examples folder of the repository.

Features and Support

EVM-Compatible Chains

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"] }

Polygon

Ethers-rs provides abigen support for Polygon and the Mumbai test network. Set the POLYGONSCAN_API_KEY environment variable to utilize this feature.

Avalanche

For Avalanche and the Fuji test network, ethers-rs includes abigen support. Configure the SNOWTRACE_API_KEY environment variable for optimal functionality.

Optimism

Enable Optimism support via the optimism feature flag:

[dependencies]
ethers = { version = "2.0", features = ["optimism"] }

Optimism introduces new transaction types requiring additional fields:

  • sourceHash
  • mint
  • isSystemTx

Celo

Ethers-rs supports Celo through the celo feature flag:

[dependencies]
ethers = { version = "2.0", features = ["celo"] }

Celo transactions include unique fields:

  • fee_currency
  • gateway_fee_recipient
  • gateway_fee

Additional Features

Ethers-rs is equipped with various other functionalities:

  • Websockets: Enable via ws feature flag.
  • IPC: Enable via ipc feature flag.
  • HTTPS Support: Choose between rustls and openssl feature flags for secure connections.
  • Hardware Wallet Support: Interact with hardware wallets securely.
  • Parity and Geth APIs: Integrate with advanced node APIs like Parity's tracing and Geth's TxPool.

Websockets

Enable Websockets support:

[dependencies]
ethers = { version = "2.0", features = ["ws"] }

Interprocess Communication (IPC)

Enable IPC support:

[dependencies]
ethers = { version = "2.0", features = ["ipc"] }

HTTPS Support

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"] }

Note on WASM and FFI Bindings

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.

Similar Projects