gleeth/ethereum/abi/types
Solidity ABI type system for encoding and decoding.
AbiType describes the shape of a value (e.g. Uint(256), Address,
Array(Bool)). AbiValue carries an actual value of that shape. Use
these with abi/encode and abi/decode to produce and consume raw
calldata.
Examples
// Describe a transfer(address, uint256) signature
let types = [Address, Uint(256)]
// Construct the values
let values = [
AddressValue("0x70997970C51812dc3A010C7d01b50e0d17dc79C8"),
UintValue(1000000),
]
Types
Errors that can occur during ABI encoding, decoding, or type parsing.
pub type AbiError {
TypeParseError(String)
EncodeError(String)
DecodeError(String)
InvalidAbiJson(String)
}
Constructors
-
TypeParseError(String)Failed to parse a Solidity type string (e.g.
"uint999"). -
EncodeError(String)Failed to encode a value (type mismatch, value out of range).
-
DecodeError(String)Failed to decode calldata (truncated data, invalid encoding).
-
InvalidAbiJson(String)Failed to parse a JSON ABI file.
Describes a Solidity ABI type. Maps directly to the Solidity type system.
pub type AbiType {
Uint(size: Int)
Int(size: Int)
Address
Bool
FixedBytes(size: Int)
Bytes
String
Array(element: AbiType)
FixedArray(element: AbiType, size: Int)
Tuple(elements: List(AbiType))
}
Constructors
-
Uint(size: Int)Unsigned integer (
uint8throughuint256). Size is in bits, must be a multiple of 8. -
Int(size: Int)Signed integer (
int8throughint256). Size is in bits. -
Address20-byte Ethereum address.
-
BoolBoolean value.
-
FixedBytes(size: Int)Fixed-size byte array (
bytes1throughbytes32). Size is in bytes. -
BytesDynamic-length byte array (
bytes). -
StringDynamic-length UTF-8 string.
-
Array(element: AbiType)Dynamic-length array of a single element type (
T[]). -
FixedArray(element: AbiType, size: Int)Fixed-length array of a single element type (
T[k]). -
Tuple(elements: List(AbiType))Tuple of heterogeneous types, e.g.
(address, uint256, bool).
A concrete value matching an AbiType. Passed to abi/encode.encode
and returned by abi/decode.decode.
pub type AbiValue {
UintValue(Int)
IntValue(Int)
AddressValue(String)
BoolValue(Bool)
FixedBytesValue(BitArray)
BytesValue(BitArray)
StringValue(String)
ArrayValue(List(AbiValue))
TupleValue(List(AbiValue))
}
Constructors
-
UintValue(Int)Unsigned integer value. Must fit within the bit size of the corresponding
Uinttype. -
IntValue(Int)Signed integer value.
-
AddressValue(String)Ethereum address as a hex string with
0xprefix. -
BoolValue(Bool)Boolean value.
-
FixedBytesValue(BitArray)Fixed-size byte array.
-
BytesValue(BitArray)Dynamic-length byte array.
-
StringValue(String)UTF-8 string value.
-
ArrayValue(List(AbiValue))Array of values (used for both
ArrayandFixedArraytypes). -
TupleValue(List(AbiValue))Tuple of heterogeneous values.
Values
pub fn head_size(t: AbiType) -> Int
Number of bytes this type occupies in the head region of a tuple encoding. Static types are encoded inline (possibly > 32 bytes for arrays/tuples). Dynamic types get a 32-byte offset pointer.
pub fn is_dynamic(t: AbiType) -> Bool
Returns True if the type uses dynamic (offset-based) ABI encoding.
Static types (uint, int, address, bool, bytesN) are encoded
inline. Dynamic types (bytes, string, T[]) use a 32-byte offset
pointer in the head region.