An Interface abstracts many of the low-level details for encoding and decoding the data on the blockchain.

An ABI provides information on how to encode data to send to a Contract, how to decode the results and events and how to interpret revert errors.

The ABI can be specified by any supported format.

Constructors

new Interface()

new Interface(fragments): Interface

Create a new Interface for the fragments.

Parameters

ParameterTypeDescription
fragmentsInterfaceAbiThe ABI fragments.

Returns

Interface

Source

abi/interface.ts:342

Properties

PropertyModifierTypeDescription
deployreadonlyConstructorFragmentThe Contract constructor.
fallbackreadonlynull | FallbackFragmentThe Fallback method, if any.
fragmentsreadonlyreadonly Fragment[]All the Contract ABI members (i.e. methods, events, errors, etc).
receivereadonlybooleanIf receiving ether is supported.

Methods

decodeErrorResult()

decodeErrorResult(fragment, data): Result

Decodes the result data (e.g. from an quai_call) for the specified error (see getError for valid values for key).

Most developers should prefer the parseCallResult | parseCallResult method instead, which will automatically detect a CALL_EXCEPTION and throw the corresponding error.

Parameters

ParameterType
fragmentstring | ErrorFragment
dataBytesLike

Returns

Result

Source

abi/interface.ts:826


decodeFunctionData()

decodeFunctionData(fragment, data): Result

Decodes the data from a transaction tx.data for the function specified (see getFunction for valid values for fragment).

Most developers should prefer the parseTransaction method instead, which will automatically detect the fragment.

Parameters

ParameterType
fragmentstring | FunctionFragment
dataBytesLike

Returns

Result

Source

abi/interface.ts:866


decodeFunctionResult()

decodeFunctionResult(fragment, data): Result

Decodes the result data (e.g. from an quai_call) for the specified function (see getFunction for valid values for key).

Most developers should prefer the parseCallResult | parseCallResult method instead, which will automatically detect a CALL_EXCEPTION and throw the corresponding error.

Parameters

ParameterType
fragmentstring | FunctionFragment
dataBytesLike

Returns

Result

Source

abi/interface.ts:904


encodeDeploy()

encodeDeploy(values?): string

Encodes a tx.data object for deploying the Contract with the values as the constructor arguments.

Parameters

ParameterType
values?readonly any[]

Returns

string

Source

abi/interface.ts:815


encodeErrorResult()

encodeErrorResult(fragment, values?): string

Encodes the transaction revert data for a call result that reverted from the the Contract with the sepcified error (see getError for valid values for fragment) with the values.

This is generally not used by most developers, unless trying to mock a result from a Contract.

Parameters

ParameterType
fragmentstring | ErrorFragment
values?readonly any[]

Returns

string

Source

abi/interface.ts:849


encodeFunctionData()

encodeFunctionData(fragment, values?): string

Encodes the tx.data for a transaction that calls the function specified (see getFunction for valid values for fragment) with the values.

Parameters

ParameterType
fragmentstring | FunctionFragment
values?readonly any[]

Returns

string

Source

abi/interface.ts:887


encodeFunctionResult()

encodeFunctionResult(fragment, values?): string

Encodes the result data (e.g. from an quai_call) for the specified function (see getFunction for valid values for fragment) with values.

This is generally not used by most developers, unless trying to mock a result from a Contract.

Parameters

ParameterType
fragmentstring | FunctionFragment
values?readonly any[]

Returns

string

Source

abi/interface.ts:975


forEachError()

forEachError(callback): void

Iterate over all errors, calling callback, sorted by their name.

Parameters

ParameterType
callback(func, index) => void

Returns

void

Source

abi/interface.ts:789


forEachEvent()

forEachEvent(callback): void

Iterate over all events, calling callback, sorted by their name.

Parameters

ParameterType
callback(func, index) => void

Returns

void

Source

abi/interface.ts:708


forEachFunction()

forEachFunction(callback): void

Iterate over all functions, calling callback, sorted by their name.

Parameters

ParameterType
callback(func, index) => void

Returns

void

Source

abi/interface.ts:595


format()

format(minimal?): string[]

Returns the entire Human-Readable ABI, as an array of signatures, optionally as minimal strings, which removes parameter names and unneceesary spaces.

Parameters

ParameterType
minimal?boolean

Returns

string[]

Source

abi/interface.ts:438


formatJson()

formatJson(): string

Return the JSON-encoded ABI. This is the format Solidiy returns.

Returns

string

Source

abi/interface.ts:447


getAbiCoder()

getAbiCoder(): AbiCoder

The ABI coder that will be used to encode and decode binary data.

Returns

AbiCoder

Source

abi/interface.ts:457


getError()

getError(key, values?): null | ErrorFragment

Get the ErroFragment for key, which may be an error selector, error name or error signature that belongs to the ABI.

If values is provided, it will use the Typed API to handle ambiguous cases where multiple errors match by name.

If the key and values do not refine to a single error in the ABI, this will throw.

Parameters

ParameterType
keystring
values?any[]

Returns

null | ErrorFragment

Source

abi/interface.ts:727


getEvent()

getEvent(key, values?): null | EventFragment

Get the EventFragment for key, which may be a topic hash, event name or event signature that belongs to the ABI.

If values is provided, it will use the Typed API to handle ambiguous cases where multiple events match by name.

If the key and values do not refine to a single event in the ABI, this will throw.

Parameters

ParameterType
keystring
values?any[]

Returns

null | EventFragment

Source

abi/interface.ts:701


getEventName()

getEventName(key): string

Get the event name for key, which may be a topic hash, event name or event signature that belongs to the ABI.

Parameters

ParameterType
keystring

Returns

string

Source

abi/interface.ts:676


getFunction()

getFunction(key, values?): null | FunctionFragment

Get the FunctionFragment for key, which may be a function selector, function name or function signature that belongs to the ABI.

If values is provided, it will use the Typed API to handle ambiguous cases where multiple functions match by name.

If the key and values do not refine to a single function in the ABI, this will throw.

Parameters

ParameterType
keystring
values?any[]

Returns

null | FunctionFragment

Source

abi/interface.ts:588


getFunctionName()

getFunctionName(key): string

Get the function name for key, which may be a function selector, function name or function signature that belongs to the ABI.

Parameters

ParameterType
keystring

Returns

string

Source

abi/interface.ts:563


hasEvent()

hasEvent(key): boolean

Returns true if key (an event topic hash, event name or event signature) is present in the ABI.

In the case of an event name, the name may be ambiguous, so accessing the EventFragment may require refinement.

Parameters

ParameterType
keystring

Returns

boolean

Source

abi/interface.ts:689


hasFunction()

hasFunction(key): boolean

Returns true if key (a function selector, function name or function signature) is present in the ABI.

In the case of a function name, the name may be ambiguous, so accessing the FunctionFragment may require refinement.

Parameters

ParameterType
keystring

Returns

boolean

Source

abi/interface.ts:575


parseError()

parseError(data): null | ErrorDescription

Parses a revert data, finding the matching error and extracts the parameter values along with other useful error details.

If the matching error cannot be found, returns null.

Parameters

ParameterType
dataBytesLike

Returns

null | ErrorDescription

Source

abi/interface.ts:1241


parseLog()

parseLog(log): null | LogDescription

Parses a receipt log, finding the matching event and extracts the parameter values along with other useful event details.

If the matching event cannot be found, returns null.

Parameters

ParameterType
logobject
log.datastring
log.topicsstring[]

Returns

null | LogDescription

Source

abi/interface.ts:1221


parseTransaction()

parseTransaction(tx): null | TransactionDescription

Parses a transaction, finding the matching function and extracts the parameter values along with other useful function details.

If the matching function cannot be found, return null.

Parameters

ParameterType
txobject
tx.datastring
tx.value?BigNumberish

Returns

null | TransactionDescription

Source

abi/interface.ts:1195


from()

static from(value): Interface

Creates a new Interface from the ABI value.

The value may be provided as an existing Interface object, a JSON-encoded ABI or any Human-Readable ABI format.

Parameters

ParameterType
valueInterface | InterfaceAbi

Returns

Interface

Source

abi/interface.ts:1260