The AbiCoder is a low-level class responsible for encoding JavaScript values into binary data and decoding binary data into JavaScript values.

Methods

decode()

decode(
   types, 
   data, 
   loose?): Result

Decode the ABI data as the types into values.

If loose decoding is enabled, then strict padding is not enforced. Some older versions of Solidity incorrectly padded event data emitted from external functions.

Parameters

ParameterTypeDescription
typesreadonly (string | ParamType)[]Array of parameter types.
dataBytesLikeThe ABI data to decode.
loose?booleanEnable loose decoding. Default is false

Returns

Result

The decoded values.

Source

abi/abi-coder.ts:223


encode()

encode(types, values): string

Encode the values as the specified types into ABI data.

Parameters

ParameterTypeDescription
typesreadonly (string | ParamType)[]Array of parameter types.
valuesreadonly any[]Array of values to encode.

Returns

string

The encoded data in hexadecimal format.

Source

abi/abi-coder.ts:201


getDefaultValue()

getDefaultValue(types): Result

Get the default values for the given types. For example, a uint is by default 0 and bool is by default false.

Parameters

ParameterTypeDescription
typesreadonly (string | ParamType)[]Array of parameter types to get default values for.

Returns

Result

The default values corresponding to the given types.

Source

abi/abi-coder.ts:188


defaultAbiCoder()

static defaultAbiCoder(): AbiCoder

Returns the shared singleton instance of a default AbiCoder.

On the first call, the instance is created internally.

Returns

AbiCoder

The default ABI coder instance.

Source

abi/abi-coder.ts:252


getBuiltinCallException()

static getBuiltinCallException(
   action, 
   tx, 
   data): CallExceptionError

Returns a quais-compatible CallExceptionError for the given result data.

Parameters

ParameterTypeDescription
actionCallExceptionActionThe action that triggered the exception.
txobjectThe transaction information.
tx.data?string-
tx.from?null | string-
tx.to?null | string-
datanull | BytesLikeThe data associated with the call exception.

Returns

CallExceptionError

The corresponding call exception error.

Source

abi/abi-coder.ts:267