Skip to content

AbiParameters.from

Parses arbitrary JSON ABI Parameters or Human Readable ABI Parameters into typed AbiParameters.AbiParameters.

Imports

Named
import { AbiParameters } from 'ox'

Examples

JSON Parameters

import { AbiParameters } from 'ox'
 
const parameters = AbiParameters.from([
  {
    name: 'spender',
    type: 'address',
  },
  {
    name: 'amount',
    type: 'uint256',
  },
])
 
const parameters: readonly [{ readonly name: "spender"; readonly type: "address"; }, { readonly name: "amount"; readonly type: "uint256"; }]
parameters

Human Readable Parameters

Human Readable ABI Parameters can be parsed into a typed AbiParameters.AbiParameters:

import { AbiParameters } from 'ox'
 
const parameters = AbiParameters.from('address spender, uint256 amount')
 
const parameters: readonly [{ readonly type: "address"; readonly name: "spender"; }, { readonly type: "uint256"; readonly name: "amount"; }]
parameters

It is possible to specify structs along with your definitions:

import { AbiParameters } from 'ox'
 
const parameters = AbiParameters.from([
  'struct Foo { address spender; uint256 amount; }',
  'Foo foo, address bar',
])
 
const parameters: readonly [{ readonly type: "tuple"; readonly components: readonly [{ readonly type: "address"; readonly name: "spender"; }, { readonly type: "uint256"; readonly name: "amount"; }]; readonly name: "foo"; }, { ...; }]
parameters

Definition

function from<parameters>(
  parameters: parameters | AbiParameters | string | readonly string[],
): from.ReturnType<parameters>

Source: src/AbiParameters.ts

Parameters

parameters

  • Type: parameters | AbiParameters | string | readonly string[]

The ABI Parameters to parse.

Return Type

The typed ABI Parameters.

from.ReturnType<parameters>