Crate alloy_primitives  
Expand description
§alloy-primitives
Primitive types shared by alloy, foundry, revm, and reth.
§Types
- Unsigned integers re-exported from ruint
- Signed integers, as a wrapper around ruintintegers
- Fixed-size byte arrays via FixedBytes- wrap_fixed_bytes!: macro for constructing named fixed bytes types
- Address, which is a fixed-size byte array of 20 bytes, with EIP-55 and EIP-1191 checksum support
- fixed_bytes!,- address!and other macros to construct the types at compile time
 
§Examples
This library has straightforward, basic, types. Usage is correspondingly simple. Please consult the documentation for more information.
use alloy_primitives::{address, fixed_bytes, Address, FixedBytes, I256, U256};
// FixedBytes
let n: FixedBytes<6> = fixed_bytes!("0x1234567890ab");
assert_eq!(n, "0x1234567890ab".parse::<FixedBytes<6>>().unwrap());
assert_eq!(n.to_string(), "0x1234567890ab");
// Uint
let mut n: U256 = "42".parse().unwrap();
n += U256::from(10);
assert_eq!(n.to_string(), "52");
// Signed
let mut n: I256 = "-42".parse().unwrap();
n = -n;
assert_eq!(n.to_string(), "42");
// Address
let addr_str = "0x66f9664f97F2b50F62D13eA064982f936dE76657";
let addr: Address = Address::parse_checksummed(addr_str, None).unwrap();
assert_eq!(addr, address!("0x66f9664f97F2b50F62D13eA064982f936dE76657"));
assert_eq!(addr.to_checksum(None), addr_str);
// Address checksummed with a custom chain id
let addr_str = "0x66F9664f97f2B50F62d13EA064982F936de76657";
let addr: Address = Address::parse_checksummed(addr_str, Some(30)).unwrap();
assert_eq!(addr, address!("0x66F9664f97f2B50F62d13EA064982F936de76657"));
assert_eq!(addr.to_checksum(Some(30)), addr_str);Modules§
- aliases
- Type aliases for common primitive types.
- ruint
- Rust uintcrate using const-generics
- storage
- Seismic’s storage
- utils
- Common Ethereum utilities.
Macros§
- address
- Converts a sequence of string literals containing hex-encoded data
into a new Addressat compile time.
- b64
- Converts a sequence of string literals containing hex-encoded data
into a new B64at compile time.
- b128
- Converts a sequence of string literals containing hex-encoded data
into a new B128at compile time.
- b256
- Converts a sequence of string literals containing hex-encoded data
into a new B256at compile time.
- b512
- Converts a sequence of string literals containing hex-encoded data
into a new B512at compile time.
- bloom
- Converts a sequence of string literals containing hex-encoded data
into a new Bloomat compile time.
- bytes
- Converts a sequence of string literals containing hex-encoded data into a
new Bytesat compile time.
- fixed_bytes 
- Converts a sequence of string literals containing hex-encoded data
into a new FixedBytesat compile time.
- hex
- Macro for converting sequence of string literals containing hex-encoded data into an array of bytes.
- try_vec
- Tries to create a Veccontaining the arguments.
- wrap_fixed_ bytes 
- Wrap a fixed-size byte array in a newtype, delegating all methods to the
underlying crate::FixedBytes.
Structs§
- Address
- An Ethereum address, 20 bytes in length.
- AddressChecksum Buffer 
- Stack-allocated buffer for efficiently computing address checksums.
- BigIntConversion Error 
- The error type that is returned when conversion to or from a integer fails.
- Bloom
- Ethereum 256 byte bloom filter.
- Bytes
- Wrapper type around [bytes::Bytes] to support “0x” prefixed hex strings.
- FixedBytes 
- A byte array of fixed length ([u8; N]).
- FlaggedStorage 
- A storage value that can be either private or public.
- Function
- An Ethereum ABI function pointer, 24 bytes in length.
- Keccak256
- Simple Keccak-256hasher.
- Log
- A log consists of an address, and some log data.
- LogData
- An Ethereum event log object.
- SAddress
- Seismic-shielded address type. Preimage is an address
- Sealed
- A consensus hashable item, with its memoized hash.
- Signature
- An Ethereum ECDSA signature.
- Signed
- Signed integer wrapping a ruint::Uint.
- Uint
- The ring of numbers modulo $2^{\mathtt{BITS}}$.
Enums§
- AddressError 
- Error type for address checksum validation.
- BloomInput 
- Input to the Bloom::accruemethod.
- ParseSigned Error 
- The error type that is returned when parsing a signed integer.
- Sign
- Enum to represent the sign of a 256-bit signed integer.
- SignatureError 
- Errors in signature parsing or verification.
- TxKind
- The tofield of a transaction. Either a target address, or empty for a contract creation.
Constants§
- BLOOM_BITS_ PER_ ITEM 
- Number of bits to set per input in Ethereum bloom filter.
- BLOOM_SIZE_ BITS 
- Size of the bloom filter in bits
- BLOOM_SIZE_ BYTES 
- Size of the bloom filter in bytes.
- KECCAK256_ EMPTY 
- The Keccak-256 hash of the empty string "".
Traits§
- IntoLogData 
- Trait for an object that can be converted into a log data object.
- PrivateSlot 
- Extends the StorageSlottrait to include a privacy flag
- Sealable
- Sealeable objects.
- StorageSlot 
- A word of data that can be stored in a storage slot
Functions§
- eip191_hash_ message 
- Hash a message according to EIP-191 (version 0x01).
- keccak256
- Simple interface to the Keccak-256hash function.
- logs_bloom 
- Compute the logs bloom filter for the given logs.
- normalize_v 
- Attempts to normalize the v value to a boolean parity value.
- to_eip155_ v 
- Applies EIP-155.
Type Aliases§
- B64
- 8-byte fixed byte-array type.
- B128
- 16-byte fixed byte-array type.
- B160Deprecated 
- 20-byte fixed byte-array type.
- B256
- 32-byte fixed byte-array type.
- B512
- 64-byte fixed byte-array type.
- BlockHash 
- A block hash.
- BlockNumber 
- A block number.
- BlockTimestamp 
- A block timestamp.
- ChainId
- Chain identifier type (introduced in EIP-155).
- I8
- 8-bit signed integer type, consisting of 1, 64-bit limbs.
- I16
- 16-bit signed integer type, consisting of 1, 64-bit limbs.
- I32
- 32-bit signed integer type, consisting of 1, 64-bit limbs.
- I64
- 64-bit signed integer type, consisting of 1, 64-bit limbs.
- I128
- 128-bit signed integer type, consisting of 2, 64-bit limbs.
- I160
- 160-bit signed integer type, consisting of 3, 64-bit limbs.
- I256
- 256-bit signed integer type, consisting of 4, 64-bit limbs.
- PrimitiveSignature Deprecated 
- Deprecated alias for Signature.
- SI8
- 8-bit [seismic signed integer type][Sint], where the preimage is a signed integer with 8 bits.
- SI16
- 16-bit [seismic signed integer type][Sint], where the preimage is a signed integer with 16 bits.
- SI32
- 32-bit [seismic signed integer type][Sint], where the preimage is a signed integer with 32 bits.
- SI64
- 64-bit [seismic signed integer type][Sint], where the preimage is a signed integer with 64 bits.
- SI128
- 128-bit [seismic signed integer type][Sint], where the preimage is a signed integer with 128 bits.
- SI256
- 256-bit [seismic signed integer type][Sint], where the preimage is a signed integer with 256 bits.
- SU8
- 8-bit [seismic unsigned integer type][Suint], where the preimage is an unsigned integer with 8 bits.
- SU16
- 16-bit [seismic unsigned integer type][Suint], where the preimage is an unsigned integer with 16 bits.
- SU32
- 32-bit [seismic unsigned integer type][Suint], where the preimage is an unsigned integer with 32 bits.
- SU64
- 64-bit [seismic unsigned integer type][Suint], where the preimage is an unsigned integer with 64 bits.
- SU128
- 128-bit [seismic unsigned integer type][Suint], where the preimage is an unsigned integer with 128 bits.
- SU256
- 256-bit [seismic unsigned integer type][Suint], where the preimage is an unsigned integer with 256 bits.
- Selector
- Solidity contract functions are addressed using the first four bytes of the Keccak-256 hash of their signature.
- StorageKey 
- An account storage key.
- StorageValue 
- An account storage value.
- TxHash
- A transaction hash is a keccak hash of an RLP encoded signed transaction.
- TxIndex
- The index of transaction in a block.
- TxNonce
- The nonce of a transaction.
- TxNumber
- The sequence number of all existing transactions.
- U8
- 8-bit unsigned integer type, consisting of 1, 64-bit limbs.
- U16
- 16-bit unsigned integer type, consisting of 1, 64-bit limbs.
- U32
- 32-bit unsigned integer type, consisting of 1, 64-bit limbs.
- U64
- 64-bit unsigned integer type, consisting of 1, 64-bit limbs.
- U128
- 128-bit unsigned integer type, consisting of 2, 64-bit limbs.
- U160
- 160-bit unsigned integer type, consisting of 3, 64-bit limbs.
- U256
- 256-bit unsigned integer type, consisting of 4, 64-bit limbs.
- U512
- 512-bit unsigned integer type, consisting of 8, 64-bit limbs.