Crate alloy_primitives
Available on crate feature
evm only.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
FixedByteswrap_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!("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);Re-exports§
pub use alloy_primitives::B64;pub use alloy_primitives::B128;pub use alloy_primitives::B256;pub use alloy_primitives::B512;pub use alloy_primitives::BlockHash;pub use alloy_primitives::BlockNumber;pub use alloy_primitives::BlockTimestamp;pub use alloy_primitives::ChainId;pub use alloy_primitives::I8;pub use alloy_primitives::I16;pub use alloy_primitives::I32;pub use alloy_primitives::I64;pub use alloy_primitives::I128;pub use alloy_primitives::I160;pub use alloy_primitives::I256;pub use alloy_primitives::Selector;pub use alloy_primitives::StorageKey;pub use alloy_primitives::StorageValue;pub use alloy_primitives::TxHash;pub use alloy_primitives::TxIndex;pub use alloy_primitives::TxNonce;pub use alloy_primitives::TxNumber;pub use alloy_primitives::U8;pub use alloy_primitives::U16;pub use alloy_primitives::U32;pub use alloy_primitives::U64;pub use alloy_primitives::U128;pub use alloy_primitives::U160;pub use alloy_primitives::U256;pub use alloy_primitives::U512;pub use alloy_primitives::ruint;pub use alloy_primitives::Uint;
Modules§
- aliases
- Type aliases for common primitive types.
- map
map - Re-exports of map types and utilities.
- 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.
- Address
Checksum Buffer - Stack-allocated buffer for efficiently computing address checksums.
- BigInt
Conversion 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. - Fixed
Bytes - A byte array of fixed length (
[u8; N]). - 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.
- Sealed
- A consensus hashable item, with its memoized hash.
- Signature
- An Ethereum ECDSA signature.
- Signed
- Signed integer wrapping a
ruint::Uint.
Enums§
- Address
Error - Error type for address checksum validation.
- Bloom
Input - Input to the
Bloom::accruemethod. - Parse
Signed Error - The error type that is returned when parsing a signed integer.
- Sign
- Enum to represent the sign of a 256-bit signed integer.
- Signature
Error - 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.
- KECCA
K256_ EMPTY - The Keccak-256 hash of the empty string
"".
Traits§
- Fixed
Bytes Slice Ext - Extension trait for flattening a slice of
FixedBytesto a byte slice. - Fixed
Bytes VecExt - Extension trait for flattening a
VecofFixedBytesto aVec<u8>. - Into
LogData - Trait for an object that can be converted into a log data object.
- Sealable
- Sealeable objects.
Functions§
- eip191_
hash_ message - Hash a message according to EIP-191 (version
0x01). - keccak256
- Simple interface to the
Keccak-256hash function. - keccak256_
uncached - 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.