Class MoveVector<T>

This class is the Aptos Typescript SDK representation of a Move vector<T>, where T represents either a primitive type (bool, u8, u64, ...) or a BCS-serializable struct itself.

It is a BCS-serializable, array-like type that contains an array of values of type T, where T is a class that implements Serializable.

The purpose of this class is to facilitate easy construction of BCS-serializable Move vector<T> types.

// in Move: `vector<u8> [1, 2, 3, 4];`
const vecOfU8s = new MoveVector<U8>([new U8(1), new U8(2), new U8(3), new U8(4)]);
// in Move: `std::bcs::to_bytes(vector<u8> [1, 2, 3, 4]);`
const bcsBytes = vecOfU8s.toUint8Array();

// vector<vector<u8>> [ vector<u8> [1], vector<u8> [1, 2, 3, 4], vector<u8> [5, 6, 7, 8] ];
const vecOfVecs = new MoveVector<MoveVector<U8>>([
new MoveVector<U8>([new U8(1)]),
MoveVector.U8([1, 2, 3, 4]),
MoveVector.U8([5, 6, 7, 8]),
]);

// vector<Option<u8>> [ std::option::some<u8>(1), std::option::some<u8>(2) ];
const vecOfOptionU8s = new MoveVector<MoveOption<U8>>([
MoveOption.U8(1),
MoveOption.U8(2),
]);

// vector<MoveString> [ std::string::utf8(b"hello"), std::string::utf8(b"world") ];
const vecOfStrings = new MoveVector([new MoveString("hello"), new MoveString("world")]);
const vecOfStrings2 = MoveVector.MoveString(["hello", "world"]);

values: an Array of values where T is a class that implements Serializable

a MoveVector<T> with the values values

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.

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

    Returns string

    the hex formatas a string prefixed by 0x.

  • Factory method to generate a MoveVector from a boolean or undefined. This method allows you to create an optional boolean value that can be used in various contexts where a boolean may or may not be present.

    Parameters

    • values: boolean[]

      The value used to fill the MoveVector. If value is undefined, the resulting MoveVector's .isSome() method will return false.

    Returns MoveVector<Bool>

    A MoveVector with an inner value value.

    * const v = MoveVector.Bool([true, false, true, false]);
    
  • Deserialize a MoveVector of type T, specifically where T is a Serializable and Deserializable type.

    NOTE: This only works with a depth of one. Generics will not work.

    NOTE: This will not work with types that aren't of the Serializable class.

    If you're looking for a more flexible deserialization function, you can use the deserializeVector function in the Deserializer class.

    Type Parameters

    Parameters

    • deserializer: Deserializer

      the Deserializer instance to use, with bytes loaded into it already.

    • cls: Deserializable<T>

      the class to typecast the input values to, must be a Serializable and Deserializable type.

    Returns MoveVector<T>

    a MoveVector of the corresponding class T

    const vec = MoveVector.deserialize(deserializer, U64);
    
  • Factory method to generate a MoveVector from a string or undefined. This function creates a MoveVector that encapsulates a MoveString if the provided value is not null or undefined.

    Parameters

    • values: string[]

      The value used to fill the MoveVector. If value is undefined, the resulting MoveVector's .isSome() method will return false.

    Returns MoveVector<MoveString>

    A MoveVector with an inner value value.

    const v = MoveVector.MoveString(["hello", "world"]);
    
  • Factory method to generate a MoveVector from a number, bigint, or undefined.

    Parameters

    • values: AnyNumber[]

      The value used to fill the MoveVector. If value is undefined, the resulting MoveVector's .isSome() method will return false.

    Returns MoveVector<U128>

    A MoveVector with an inner value value.

    const v = MoveVector.U128([1, 2, 3, 4]);
    
  • Factory method to generate a MoveOption from a number or null.

    This method allows you to create a MoveVector that can either hold a U16 value or be empty.

    Parameters

    • values: number[]

      The value used to fill the MoveVector. If value is null or undefined, the resulting MoveVector's .isSome() method will return false.

    Returns MoveVector<U16>

    A MoveVector with an inner value value.

    const v = MoveVector.U16([1, 2, 3, 4]);
    
  • Factory method to generate a MoveVector from a number, bigint, or null/undefined. This allows for the creation of an optional U256 value, enabling checks for presence or absence of a value.

    Parameters

    • values: AnyNumber[]

      The value used to fill the MoveVector. If value is undefined or null, the resulting MoveVector's .isSome() method will return false.

    Returns MoveVector<U256>

    A MoveVector with an inner value value.

    const v = MoveVector.U256([1, 2, 3, 4]);
    
  • Factory method to generate a MoveVector from a number or null.

    This method allows you to create a MoveVector that can either hold a U32 value or be empty.

    Parameters

    • values: number[]

      The value used to fill the MoveVector. If value is null or undefined, the resulting MoveVector's .isSome() method will return false.

    Returns MoveVector<U32>

    A MoveVector with an inner value value.

    const v = MoveVector.U32([1, 2, 3, 4]);
    
  • Factory method to generate a MoveVector from a number, bigint, or null/undefined. This allows for the creation of an optional U64 value that can be checked for presence.

    Parameters

    • values: AnyNumber[]

      The value used to fill the MoveVector. If value is undefined or null, the resulting MoveVector's .isSome() method will return false.

    Returns MoveVector<U64>

    A MoveVector with an inner value value.

    const v = MoveVector.U64([1, 2, 3, 4]);
    
  • Factory method to generate a MoveVector from a number or undefined.

    This method allows you to create a MoveVector that encapsulates a U8 value, enabling you to handle optional U8 values effectively.

    Parameters

    • values: HexInput | number[]

      The values used to fill the MoveVector. If values is undefined or null, the resulting MoveVector's .isSome() method will return false.

    Returns MoveVector<U8>

    A MoveVector with an inner value value.

    const v = MoveVector.U8([1, 2, 3, 4]);
    

Properties

values: T[]