Skip to main content

decodeParameter

Callable

  • decodeParameter(abi: AbiInput, bytes: string): unknown

  • Decodes an ABI encoded parameter to its JavaScript type.

    @example
      const res = web3.eth.abi.decodeParameter(
    "uint256",
    "0x0000000000000000000000000000000000000000000000000000000000000010"
    );
    console.log(res);
    > 16n

    const res = web3.eth.abi.decodeParameter(
    "string",
    "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000848656c6c6f212521000000000000000000000000000000000000000000000000"
    );

    console.log(res);
    > Hello!%!

    const res = web3.eth.abi.decodeParameter(
    {
    ParentStruct: {
    propertyOne: "uint256",
    propertyTwo: "uint256",
    childStruct: {
    propertyOne: "uint256",
    propertyTwo: "uint256",
    },
    },
    },
    "0x000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000002d000000000000000000000000000000000000000000000000000000000000004e"
    );

    console.log(res);
    {
    '0': 42n,
    '1': 56n,
    '2': {
    '0': 45n,
    '1': 78n,
    __length__: 2,
    propertyOne: 45n,
    propertyTwo: 78n
    },
    __length__: 3,
    propertyOne: 42n,
    propertyTwo: 56n,
    childStruct: {
    '0': 45n,
    '1': 78n,
    __length__: 2,
    propertyOne: 45n,
    propertyTwo: 78n
    }
    }

    Parameters

    Returns unknown

    • The decoded parameter