ByteSerializeParams¶
- arbitrum_py.utils.byte_serialize_params.get_address_index(address, provider)[source]¶
Check if an address is registered in the Arbitrum address table contract.
This function checks the ArbAddressTable contract to see if an address is registered. If found, returns its index. Results are memoized to avoid redundant contract calls.
- Parameters:
address (
str) – The Ethereum address to look upprovider (
Any) – Web3 provider connected to L2
- Returns:
The index if address is registered, -1 if not registered
- Return type:
int
Note
The function caches results in address_to_index_memo to optimize repeated lookups
- arbitrum_py.utils.byte_serialize_params.arg_serializer_constructor(provider)[source]¶
Create a function for serializing parameters using the Arbitrum address table.
This constructor creates a closure over a provider that can be used to serialize parameters according to the Arbitrum byte serialization schema.
- Parameters:
provider (
Any) – Web3 provider or wrapper connected to L2- Returns:
A function that takes a list of primitives or arrays and returns serialized bytes
- Return type:
Callable
Example
>>> provider = Web3(Web3.HTTPProvider('...')) >>> serializer = arg_serializer_constructor(provider) >>> result = serializer(['0x123...', 42, True])
- arbitrum_py.utils.byte_serialize_params.is_address_type(value)[source]¶
Check if a value is a valid Ethereum address.
- Parameters:
value (
Any) – Any value to check- Returns:
True if value is a string and valid Ethereum address, False otherwise
- Return type:
bool
- arbitrum_py.utils.byte_serialize_params.to_uint(val, bytes_size)[source]¶
Convert a value to a big-endian byte representation with specified size.
- Parameters:
val (
Union[str,int,bool,NewType()(Wei,int),Decimal]) – Value to convert (numeric or boolean)bytes_size (
Literal[1,4,8,16,32]) – Size of the resulting byte array (1, 4, 8, 16, or 32)
- Returns:
Big-endian representation of the value
- Return type:
bytes
Note
Booleans are converted to 1 (True) or 0 (False)
- arbitrum_py.utils.byte_serialize_params.format_primitive(value)[source]¶
Format a primitive value according to the Arbitrum byte serialization schema.
This function handles the following types: - Ethereum addresses (as 20-byte values) - Booleans (as 1 = True, 0 = False) - Numbers (as 32-byte big-endian values)
- Parameters:
value (
Union[str,int,bool,NewType()(Wei,int),Decimal]) – The primitive value to format- Returns:
Formatted byte representation
- Return type:
bytes
- Raises:
ArbSdkError – If the value type is not supported
- arbitrum_py.utils.byte_serialize_params.serialize_params(params, address_to_index=<function <lambda>>)[source]¶
Serialize parameters according to the Arbitrum byte serialization schema.
Schema for address arrays: - 1 byte: array length - 1 byte: is-registered flag (1 = all registered, 0 = not all registered) - For each address:
If registered: 4 bytes (index)
If not registered: 20 bytes (full address)
Schema for non-address arrays: - 1 byte: array length - Concatenated items (variable length)
Schema for single address: - 1 byte: is-registered flag - 4 or 20 bytes: index or address
- Parameters:
params (
List[Union[str,int,bool,NewType()(Wei,int),Decimal,List[Union[str,int,bool,NewType()(Wei,int),Decimal]]]]) – List of values to serialize (can include nested lists)address_to_index (
Callable[[str],int]) – Function to get address table index (-1 if not registered)
- Returns:
Serialized parameter data
- Return type:
bytes
Example
>>> serialize_params(['0x123...', [42, 43], True])