Skip to main content

decodeParameters

Callable

  • decodeParameters(abi: AbiInput[], bytes: string): { __length__: number }

  • Decodes ABI encoded parameters to its JavaScript types.

    @example
    let res = web3.eth.abi.decodeParameters(
    ["string", "uint256"],
    "0x000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000ea000000000000000000000000000000000000000000000000000000000000000848656c6c6f212521000000000000000000000000000000000000000000000000"
    );
    console.log(res);
    > { '0': 'Hello!%!', '1': 234n, __length__: 2 }

    let res = web3.eth.abi.decodeParameters(
    [
    {
    type: "string",
    name: "myString",
    },
    {
    type: "uint256",
    name: "myNumber",
    },
    ],
    "0x000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000ea000000000000000000000000000000000000000000000000000000000000000848656c6c6f212521000000000000000000000000000000000000000000000000"
    );
    console.log(res);
    > {
    '0': 'Hello!%!',
    '1': 234n,
    __length__: 2,
    myString: 'Hello!%!',
    myNumber: 234n
    }

    const res = web3.eth.abi.decodeParameters(
    [
    "uint8[]",
    {
    ParentStruct: {
    propertyOne: "uint256",
    propertyTwo: "uint256",
    childStruct: {
    propertyOne: "uint256",
    propertyTwo: "uint256",
    },
    },
    },
    ],
    "0x00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000002d000000000000000000000000000000000000000000000000000000000000004e0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000018"
    );
    console.log(res);
    >
    '0': [ 42n, 24n ],
    '1': {
    '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
    }
    },
    __length__: 2,
    ParentStruct: {
    '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 { __length__: number }

    • The result object containing the decoded parameters.
    • [key string]: unknown
    • __length__: number