Skip to content

AbiConstructor.from

Parses an arbitrary JSON ABI Constructor or Human Readable ABI Constructor into a typed AbiConstructor.AbiConstructor.

Imports

Named
import { AbiConstructor } from 'ox'

Examples

JSON ABIs

import { AbiConstructor } from 'ox'
 
const constructor = AbiConstructor.from({
  inputs: [
    { name: 'owner', type: 'address' },
  ],
  payable: false,
  stateMutability: 'nonpayable',
  type: 'constructor',
})
 
const constructor: { readonly inputs: readonly [{ readonly name: "owner"; readonly type: "address"; }]; readonly payable: false; readonly stateMutability: "nonpayable"; readonly type: "constructor"; }
constructor

Human Readable ABIs

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

import { AbiConstructor } from 'ox'
 
const constructor = AbiConstructor.from(
  'constructor(address owner)'
)
 
const constructor: { readonly type: "constructor"; readonly stateMutability: "nonpayable"; readonly inputs: readonly [{ readonly type: "address"; readonly name: "owner"; }]; }
constructor

It is possible to specify structs along with your definitions:

import { AbiConstructor } from 'ox'
 
const constructor = AbiConstructor.from([
  'struct Foo { address owner; uint256 amount; }',
  'constructor(Foo foo)',
])
 
const constructor: { readonly type: "constructor"; readonly stateMutability: "nonpayable"; readonly inputs: readonly [{ readonly type: "tuple"; readonly components: readonly [{ readonly type: "address"; readonly name: "owner"; }, { readonly type: "uint256"; readonly name: "amount"; }]; readonly name: "foo"; }]; }
constructor

Definition

function from(
  abiConstructor: AbiConstructor | string | readonly string[],
): AbiConstructor

Source: src/AbiConstructor.ts

Parameters

abiConstructor

  • Type: AbiConstructor | string | readonly string[]

The ABI Constructor to parse.

Return Type

Typed ABI Constructor.

AbiConstructor.AbiConstructor