Skip to content

AbiParameters.decode

Decodes ABI-encoded data into its respective primitive values based on ABI Parameters.

Imports

Named
import { AbiParameters } from 'ox'

Examples

import { AbiParameters } from 'ox'
 
const data = AbiParameters.decode(
  AbiParameters.from(['string', 'uint', 'bool']),
  '0x000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001a4000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000057761676d69000000000000000000000000000000000000000000000000000000',
)
['wagmi', 420n, true]

JSON Parameters

You can pass JSON ABI Parameters:

import { AbiParameters } from 'ox'
 
const data = AbiParameters.decode(
  [
    { name: 'x', type: 'string' },
    { name: 'y', type: 'uint' },
    { name: 'z', type: 'bool' },
  ],
  '0x000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001a4000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000057761676d69000000000000000000000000000000000000000000000000000000',
)
['wagmi', 420n, true]

Definition

function decode<parameters, as>(
  parameters: parameters,
  data: Bytes.Bytes | Hex.Hex,
  options?: decode.Options<as>,
): decode.ReturnType<parameters, as>

Source: src/core/AbiParameters.ts

Parameters

parameters

  • Type: parameters

The set of ABI parameters to decode, in the shape of the inputs or outputs attribute of an ABI Item. These parameters must include valid ABI types.

data

  • Type: Bytes.Bytes | Hex.Hex

ABI encoded data.

options

  • Type: decode.Options<as>
  • Optional

Decoding options.

options.as

  • Type: "Array" | "Object" | as
  • Optional

Whether the decoded values should be returned as an Object or Array.

Return Type

Array of decoded values.

decode.ReturnType<parameters, as>