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
ruint
integers - Fixed-size byte arrays via
FixedBytes
wrap_fixed_bytes!
: macro for constructing named fixed bytes typesAddress
, which is a fixed-size byte array of 20 bytes, with EIP-55 and EIP-1191 checksum supportfixed_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!("1234567890ab");
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!("66f9664f97F2b50F62D13eA064982f936dE76657"));
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!("66F9664f97f2B50F62d13EA064982F936de76657"));
assert_eq!(addr.to_checksum(Some(30)), addr_str);
Modules§
- Type aliases for common primitive types.
- RustCrypto: hex-literal
- map
map
Re-exports of map types and utilities. - Rust
uint
crate using const-generics - Common Ethereum utilities.
Macros§
- Converts a sequence of string literals containing hex-encoded data into a new
Address
at compile time. - Converts a sequence of string literals containing hex-encoded data into a new
B64
at compile time. - Converts a sequence of string literals containing hex-encoded data into a new
B128
at compile time. - Converts a sequence of string literals containing hex-encoded data into a new
B256
at compile time. - Converts a sequence of string literals containing hex-encoded data into a new
B512
at compile time. - Converts a sequence of string literals containing hex-encoded data into a new
Bloom
at compile time. - Converts a sequence of string literals containing hex-encoded data into a new
Bytes
at compile time. - Converts a sequence of string literals containing hex-encoded data into a new
FixedBytes
at compile time. - Macro for converting sequence of string literals containing hex-encoded data into an array of bytes.
- Tries to create a
Vec
containing the arguments. - Wrap a fixed-size byte array in a newtype, delegating all methods to the underlying
crate::FixedBytes
.
Structs§
- An Ethereum address, 20 bytes in length.
- Stack-allocated buffer for efficiently computing address checksums.
- The error type that is returned when conversion to or from a integer fails.
- Ethereum 256 byte bloom filter.
- Wrapper type around [
bytes::Bytes
] to support “0x” prefixed hex strings. - A byte array of fixed length (
[u8; N]
). - An Ethereum ABI function pointer, 24 bytes in length.
- Simple
Keccak-256
hasher. - A log consists of an address, and some log data.
- An Ethereum event log object.
- An Ethereum ECDSA signature.
- A consensus hashable item, with its memoized hash.
- An Ethereum ECDSA signature.
- Signed integer wrapping a
ruint::Uint
. - The ring of numbers modulo $2^{\mathtt{BITS}}$.
Enums§
- Error type for address checksum validation.
- Input to the
Bloom::accrue
method. - The parity of the signature, stored as either a V value (which may include a chain id), or the y-parity.
- The error type that is returned when parsing a signed integer.
- Enum to represent the sign of a 256-bit signed integer.
- Errors in signature parsing or verification.
- The
to
field of a transaction. Either a target address, or empty for a contract creation.
Constants§
- Number of bits to set per input in Ethereum bloom filter.
- Size of the bloom filter in bits
- Size of the bloom filter in bytes.
Traits§
- Trait for an object that can be converted into a log data object.
- Sealeable objects.
Functions§
- Hash a message according to EIP-191 (version
0x01
). - Simple interface to the
Keccak-256
hash function. - Compute the logs bloom filter for the given logs.
- Attempts to normalize the v value to a boolean parity value.
- Applies EIP-155.
Type Aliases§
- 8-byte fixed byte-array type.
- 16-byte fixed byte-array type.
- B160
Deprecated 20-byte fixed byte-array type. - 32-byte fixed byte-array type.
- 64-byte fixed byte-array type.
- A block hash.
- A block number.
- A block timestamp.
- Chain identifier type (introduced in EIP-155).
- 8-bit signed integer type, consisting of 1, 64-bit limbs.
- 16-bit signed integer type, consisting of 1, 64-bit limbs.
- 32-bit signed integer type, consisting of 1, 64-bit limbs.
- 64-bit signed integer type, consisting of 1, 64-bit limbs.
- 128-bit signed integer type, consisting of 2, 64-bit limbs.
- 160-bit signed integer type, consisting of 3, 64-bit limbs.
- 256-bit signed integer type, consisting of 4, 64-bit limbs.
- Solidity contract functions are addressed using the first four bytes of the Keccak-256 hash of their signature.
- An account storage key.
- An account storage value.
- A transaction hash is a keccak hash of an RLP encoded signed transaction.
- The index of transaction in a block.
- The nonce of a transaction.
- The sequence number of all existing transactions.
- 8-bit unsigned integer type, consisting of 1, 64-bit limbs.
- 16-bit unsigned integer type, consisting of 1, 64-bit limbs.
- 32-bit unsigned integer type, consisting of 1, 64-bit limbs.
- 64-bit unsigned integer type, consisting of 1, 64-bit limbs.
- 128-bit unsigned integer type, consisting of 2, 64-bit limbs.
- 160-bit unsigned integer type, consisting of 3, 64-bit limbs.
- 256-bit unsigned integer type, consisting of 4, 64-bit limbs.
- 512-bit unsigned integer type, consisting of 8, 64-bit limbs.