alloy-primitives

Primitive types shared by [alloy], [foundry], [revm], and [reth].

Types

Examples

This library has straightforward, basic, types. Usage is correspondingly simple. Please consult the documentation for more information.

```rust use alloy_primitives::{U256, Address, FixedBytes, I256};

// FixedBytes let n: FixedBytes<6> = "0x1234567890ab".parse().unwrap(); asserteq!(n.tostring(), "0x1234567890ab");

// Uint let mut n: U256 = "42".parse().unwrap(); n += U256::from(10); asserteq!(n.tostring(), "52");

// Signed let mut n: I256 = "-42".parse().unwrap(); n = -n; asserteq!(n.tostring(), "42");

// Address let addrstr = "0x66f9664f97F2b50F62D13eA064982f936dE76657"; let addr: Address = Address::parsechecksummed(addrstr, None).unwrap(); asserteq!(addr.tochecksum(None), addrstr);

// Address with custom chain id let addrstr = "0x66F9664f97f2B50F62d13EA064982F936de76657"; let addr: Address = Address::parsechecksummed(addrstr, Some(30)).unwrap(); asserteq!(addr.tochecksum(Some(30)), addrstr); ```