Class MoveOption<T>

Represents an argument for entry functions, providing methods to serialize the argument to BCS-serialized bytes and convert it to different formats.

Type Parameters

Hierarchy (view full)

Implements

Constructors

Methods

  • Converts the BCS-serialized bytes of a value into a Hex instance. This function provides a Hex representation of the BCS-serialized data for easier handling and manipulation.

    Returns Hex

    A Hex instance with the BCS-serialized bytes loaded into its underlying Uint8Array.

  • Serialize an argument to BCS-serialized bytes. Serialize an argument as a type-agnostic, fixed byte sequence. The byte sequence contains the number of the following bytes followed by the BCS-serialized bytes for a typed argument.

    Parameters

    • serializer: Serializer

      The serializer used to convert the argument.

    Returns void

  • Returns the hex string representation of the Serializable value with the 0x prefix.

    Returns string

    the hex formatas a string prefixed by 0x.

  • Retrieves the inner value of the MoveOption.

    This method is inspired by Rust's Option<T>.unwrap(), where attempting to unwrap a None value results in a panic. This method will throw an error if the value is not present.

    Returns T

    The contained value if present.

    const option = new MoveOption<Bool>(new Bool(true));
    const value = option.unwrap(); // Returns the Bool instance

    Throws an error if the MoveOption does not contain a value.

  • Factory method to generate a MoveOption from a boolean or undefined.

    Parameters

    • Optionalvalue: null | boolean

    Returns MoveOption<Bool>

    a MoveOption with an inner value value

    MoveOption.Bool(true).isSome() === true;
    MoveOption.Bool().isSome() === false;
    MoveOption.Bool(undefined).isSome() === false;

    value: the value used to fill the MoveOption. If value is undefined the resulting MoveOption's .isSome() method will return false.

  • Factory method to generate a MoveOption from a string or undefined.

    Parameters

    • Optionalvalue: null | string

    Returns MoveOption<MoveString>

    a MoveOption with an inner value value

    MoveOption.MoveString("hello").isSome() === true;
    MoveOption.MoveString("").isSome() === true;
    MoveOption.MoveString().isSome() === false;
    MoveOption.MoveString(undefined).isSome() === false;

    value: the value used to fill the MoveOption. If value is undefined the resulting MoveOption's .isSome() method will return false.

  • Factory method to generate a MoveOption from a number or a bigint or undefined.

    Parameters

    Returns MoveOption<U128>

    a MoveOption with an inner value value

    MoveOption.U128(1).isSome() === true;
    MoveOption.U128().isSome() === false;
    MoveOption.U128(undefined).isSome() === false;

    value: the value used to fill the MoveOption. If value is undefined the resulting MoveOption's .isSome() method will return false.

  • Factory method to generate a MoveOption from a number or undefined.

    Parameters

    • Optionalvalue: null | number

    Returns MoveOption<U16>

    a MoveOption with an inner value value

    MoveOption.U16(1).isSome() === true;
    MoveOption.U16().isSome() === false;
    MoveOption.U16(undefined).isSome() === false;

    value: the value used to fill the MoveOption. If value is undefined the resulting MoveOption's .isSome() method will return false.

  • Factory method to generate a MoveOption from a number or a bigint or undefined.

    Parameters

    Returns MoveOption<U256>

    a MoveOption with an inner value value

    MoveOption.U256(1).isSome() === true;
    MoveOption.U256().isSome() === false;
    MoveOption.U256(undefined).isSome() === false;

    value: the value used to fill the MoveOption. If value is undefined the resulting MoveOption's .isSome() method will return false.

  • Factory method to generate a MoveOption from a number or undefined.

    Parameters

    • Optionalvalue: null | number

    Returns MoveOption<U32>

    a MoveOption with an inner value value

    MoveOption.U32(1).isSome() === true;
    MoveOption.U32().isSome() === false;
    MoveOption.U32(undefined).isSome() === false;

    value: the value used to fill the MoveOption. If value is undefined the resulting MoveOption's .isSome() method will return false.

  • Factory method to generate a MoveOption from a number or a bigint or undefined.

    Parameters

    Returns MoveOption<U64>

    a MoveOption with an inner value value

    MoveOption.U64(1).isSome() === true;
    MoveOption.U64().isSome() === false;
    MoveOption.U64(undefined).isSome() === false;

    value: the value used to fill the MoveOption. If value is undefined the resulting MoveOption's .isSome() method will return false.

  • Factory method to generate a MoveOption from a number or undefined.

    Parameters

    • Optionalvalue: null | number

    Returns MoveOption<U8>

    a MoveOption with an inner value value

    MoveOption.U8(1).isSome() === true;
    MoveOption.U8().isSome() === false;
    MoveOption.U8(undefined).isSome() === false;

    value: the value used to fill the MoveOption. If value is undefined the resulting MoveOption's .isSome() method will return false.

Properties

value?: T