#ethers #alloy #u256 #byte #primitive #h160

alloy-ethers-typecast

Crate for safe typecasting between ethers and alloy types

2 unstable releases

0.2.0 Jan 1, 2024
0.1.0 Jan 1, 2024

#23 in #u256

Download history 7/week @ 2025-07-23 83/week @ 2025-07-30 10/week @ 2025-08-06 23/week @ 2025-08-20 99/week @ 2025-08-27 56/week @ 2025-09-03 19/week @ 2025-09-10 9/week @ 2025-09-17 5/week @ 2025-09-24 8/week @ 2025-10-01 30/week @ 2025-10-15 15/week @ 2025-10-22 5/week @ 2025-10-29 21/week @ 2025-11-05

71 downloads per month
Used in cargo-stylus-check

CAL-1.0 license

6KB
79 lines

Crate for Safe Typecasting between Ethers and Alloy types

Currently supporting type conversion for:

  • ethers::types::H160 to alloy_primitives::Address
  • alloy_primitives::Address to ethers::types::H160
  • ethers::types::U256 to alloy_primitives::U256
  • alloy_primitives::U256 to ethers::types::U256
  • ethers::types::Bytes to alloy_primitives::Bytes
  • alloy_primitives::Bytes to ethers::types::Bytes

Example

let ethers_address: ethers::types::H160 = ethers::types::H160::random();
let alloy_address: alloy_primitives::Address = ethers_address_to_alloy(ethers_address);
let ethers_u256: ethers::types::U256 = ethers::types::U256::from_dec_str("126731272983");
let alloy_u256: alloy_primitives::U256 = ethers_u256_to_alloy(ethers_u256);

Dependencies

~31–52MB
~1M SLoC