Crate alloy_primitives
source ·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!("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);Re-exports§
pub use aliases::BlockHash;pub use aliases::BlockNumber;pub use aliases::ChainId;pub use aliases::Selector;pub use aliases::StorageKey;pub use aliases::StorageValue;pub use aliases::TxHash;pub use aliases::TxIndex;pub use aliases::TxNumber;pub use aliases::B128;pub use aliases::B256;pub use aliases::B512;pub use aliases::B64;pub use aliases::I128;pub use aliases::I16;pub use aliases::I160;pub use aliases::I256;pub use aliases::I32;pub use aliases::I64;pub use aliases::I8;pub use aliases::U128;pub use aliases::U16;pub use aliases::U160;pub use aliases::U256;pub use aliases::U32;pub use aliases::U512;pub use aliases::U64;pub use aliases::U8;pub use utils::eip191_hash_message;pub use utils::keccak256;pub use utils::Keccak256;pub use ::bytes;pub use ::hex;pub use hex_literal;pub use hex_literal::hex;pub use ruint;pub use ruint::uint;pub use ruint::Uint;pub use ::hex::serde as serde_hex;serde
Modules§
- Type aliases for common primitive types.
- postgres
postgresSupport for thepostgres_typescrate. - Common Ethereum utilities.
Macros§
- Converts a sequence of string literals containing hex-encoded data into a new
Addressat compile time. - Converts a sequence of string literals containing hex-encoded data into a new
B64at compile time. - Converts a sequence of string literals containing hex-encoded data into a new
B128at compile time. - Converts a sequence of string literals containing hex-encoded data into a new
B256at compile time. - Converts a sequence of string literals containing hex-encoded data into a new
B512at compile time. - Converts a sequence of string literals containing hex-encoded data into a new
Bloomat compile time. - Converts a sequence of string literals containing hex-encoded data into a new
Bytesat compile time. - Converts a sequence of string literals containing hex-encoded data into a new
FixedBytesat compile time. - Tries to create a
Vecofnelements, each initialized toelem. - 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::Bytesto support “0x” prefixed hex strings. - A byte array of fixed length (
[u8; N]). - An Ethereum ABI function pointer, 24 bytes in length.
- A log consists of an address, and some log data.
- An Ethereum event log object.
- A consensus hashable item, with its memoized hash.
- Signed integer wrapping a
ruint::Uint.
Enums§
- Error type for address checksum validation.
- Input to the
Bloom::accruemethod. - 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
tofield 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§
- Sealeable objects.
Functions§
- Applies EIP-155.
Type Aliases§
- B160Deprecated20-byte fixed byte-array type.
- Signature
k256An ECDSA Signature, consisting of V, R, and S.