Function encodeSingle

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

    See encode 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 ABI encoded bytes.

    Type Parameters

    • Type extends string

    Parameters

    • type: Type

      The type to encode.

    • value: 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]["input"] : unknown

      The value to encode.

    Returns Uint8Array