Module abi

Source
Expand description

Ethereum ABI codec implementation.

This module provides the low-level ABI Encoder and Decoder structs, along with generic functions for their operation. These utilize an intermediate representation, referred to as tokens. For additional information about tokens, see the token module documentation.

You should not need this module in most cases, as the SolType and SolValue traits provide a higher-level and easier to use interface. If you’re sure you need the low-level functionality of this module, there are three main interfaces:

§{encode,decode}

encode operates on a single token. It wrap this token in a single-element tuple, and passes it to the encoder. Similarly, decode decodes a single token from a blob by decoding a single-element tuple.

Use this interface when ABI-encoding a single token. This is suitable for encoding a type in isolation, or for encoding parameters for single-param functions.

§{encode,decode}_params

encode_params operates on a sequence. If the sequence is a tuple, the tuple is inferred to be a set of Solidity function parameters, The corresponding decode_params reverses this operation, decoding a tuple from a blob.

This is used to encode the parameters for a Solidity function.

§{encode,decode}_sequence

encode_sequence operates on a sequence of tokens. This sequence is inferred not to be function parameters.

This is the least useful one. Most users will not need it.

Re-exports§

pub use token::Token;
pub use token::TokenSeq;

Modules§

token
Ethereum ABI tokens.

Structs§

Decoder
The Decoder wraps a byte slice with necessary info to progressively deserialize the bytes into a sequence of tokens.
Encoder
An ABI encoder.

Constants§

EMPTY_BYTES
The ABI encoding of an empty byte array (bytes or string).
RECURSION_LIMIT
The decoder recursion limit. This is currently hardcoded, but may be parameterizable in the future.

Functions§

decode
ABI-decodes a token by wrapping it in a single-element tuple.
decode_params
ABI-decodes top-level function args.
decode_sequence
Decodes ABI compliant vector of bytes into vector of tokens described by types param.
encode
ABI-encodes a single token.
encode_params
ABI-encodes a tuple as ABI function params, suitable for passing to a function.
encode_sequence
ABI-encodes a token sequence.