Skip to content

AbiEvent.from

Parses an arbitrary JSON ABI Event or Human Readable ABI Event into a typed AbiEvent.AbiEvent.

Imports

Named
import { AbiEvent } from 'ox'

Examples

JSON ABIs

import { AbiEvent } from 'ox'
 
const transfer = AbiEvent.from({
  name: 'Transfer',
  type: 'event',
  inputs: [
    { name: 'from', type: 'address', indexed: true },
    { name: 'to', type: 'address', indexed: true },
    { name: 'value', type: 'uint256' },
  ],
})
 
const transfer: { readonly name: "Transfer"; readonly type: "event"; readonly inputs: readonly [{ readonly name: "from"; readonly type: "address"; readonly indexed: true; }, { readonly name: "to"; readonly type: "address"; readonly indexed: true; }, { ...; }]; }
transfer

Human Readable ABIs

A Human Readable ABI can be parsed into a typed ABI object:

import { AbiEvent } from 'ox'
 
const transfer = AbiEvent.from(
  'event Transfer(address indexed from, address indexed to, uint256 value)'
)
 
const transfer: { readonly name: "Transfer"; readonly type: "event"; readonly inputs: readonly [{ readonly type: "address"; readonly name: "from"; readonly indexed: true; }, { readonly type: "address"; readonly name: "to"; readonly indexed: true; }, { ...; }]; }
transfer

Definition

function from<abiEvent>(
  abiEvent: (abiEvent | AbiEvent | string | readonly string[]) & ((abiEvent extends string ? internal.Signature<abiEvent> : never) | (abiEvent extends readonly string[] ? internal.Signatures<abiEvent> : never) | AbiEvent),
  options?: from.Options,
): from.ReturnType<abiEvent>

Source: src/core/AbiEvent.ts

Parameters

abiEvent

  • Type: (abiEvent | AbiEvent | string | readonly string[]) & ((abiEvent extends string ? internal.Signature<abiEvent> : never) | (abiEvent extends readonly string[] ? internal.Signatures<abiEvent> : never) | AbiEvent)

The ABI Event to parse.

options

  • Type: from.Options
  • Optional

options.prepare

  • Type: boolean
  • Optional

Whether or not to prepare the extracted event (optimization for encoding performance). When true, the hash property is computed and included in the returned value.

Return Type

Typed ABI Event.

from.ReturnType<abiEvent>