Skip to content

Reference

ethers-rs has been deprecated in favor of Alloy and Foundry.

The following is a reference guide for finding the migration path for your specific crate, dependency or information source.

Documentation

Examples

Crates

Types

Primitives

Due to a limitation in ruint, BigEndianHash ethers::types::BigEndianHash can be expressed as follows:

use alloy_primitives::{U256, B256};
// `U256` => `B256`
let x = B256::from(u256);
 
// `B256` => `U256`
let x: U256 = b256.into();
let x = U256::from_be_bytes(b256.into())

Due to Rust issue #50133, the native TryFrom trait is not supported for Uints. Instead, use UintTryFrom as follows:

use alloy_primitives::ruint::UintTryFrom;
 
let x: U512 = uint!(1234_U512);
let y: U256 = U256::uint_try_from(x).unwrap();
 
let num = U16::from(300);
// Wraps around the U16 value to fit it in the u8 type.
let x = num.wrapping_to::<u8>();
assert_eq!(x, 44);
 
// Saturates the expected type and returns the maximum value if the number is too large.
let y = num.saturating_to::<u8>();
assert_eq!(y, 255);
 
// Attempts to convert and panics if number is too large for the expected type.
let z = num.to::<u8>();

RPC

ABI