Function decodeSingle

  • Decode the data with the provided type. The type must be a valid Solidity ABI type.

    See decode for more information on how values are parsed.

    Example

    import { encodeSingle, decodeSingle } from '@metamask/abi-utils';

    const encoded = encodeSingle('uint256', 42);
    const decoded = decodeSingle('uint256', encoded);

    console.log(decoded); // 42n

    See

    https://docs.soliditylang.org/en/v0.8.17/abi-spec.html#types

    Returns

    The decoded value.

    Type Parameters

    • Type extends string

    Parameters

    • type: Type

      The type to decode.

    • value: Uint8Array | `0x${string}`

      The bytes-like value to decode.

    Returns Type extends "string" | "function" | "address" | "bytes[]" | "address[]" | "string[]" | "int[]" | "uint[]" | "bool" | "bool[]" | BytesType | IntegerType | `(${string})` | "function[]" | `bytes${number}[]` | `int${number}[]` | `uint${number}[]` | `(${string})[]` | `bytes[${number}]` | `int[${number}]` | `uint[${number}]` | `address[${number}]` | `bool[${number}]` | `function[${number}]` | `string[${number}]` | `bytes${number}[${number}]` | `int${number}[${number}]` | `uint${number}[${number}]` | `(${string})[${number}]` ? Type[Type]["output"] : unknown