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

Properties

values: T[]

Methods

  • Serializes a Serializable value to its BCS representation. This function is the Typescript SDK equivalent of bcs::to_bytes in Move.

    Returns Uint8Array

    the BCS representation of the Serializable instance as a byte buffer

  • Helper function to get a value's BCS-serialized bytes as a Hex instance.

    Returns Hex

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

  • Serialize an argument to BCS-serialized bytes.

    Parameters

    Returns void

  • 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

    Returns void

  • NOTE: This function will only work when the inner values in the MoveVector are U8s.

    Parameters

    Returns void

  • Factory method to generate a MoveVector of Bools from an array of booleans.

    Parameters

    • values: boolean[]

    Returns MoveVector<Bool>

    a MoveVector<Bool>

    const v = MoveVector.Bool([true, false, true, false]);
    

    values: an array of bools to convert to Bools

  • 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

    Returns MoveVector<T>

    a MoveVector of the corresponding class T *

    const vec = MoveVector.deserialize(deserializer, U64);
    

    deserializer: the Deserializer instance to use, with bytes loaded into it already. cls: the class to typecast the input values to, must be a Serializable and Deserializable type.

  • Factory method to generate a MoveVector of MoveStrings from an array of strings.

    Parameters

    • values: string[]

    Returns MoveVector<MoveString>

    a MoveVector<MoveString>

    const v = MoveVector.MoveString(["hello", "world"]);
    

    values: an array of strings to convert to MoveStrings

  • Factory method to generate a MoveVector of U128s from an array of numbers or bigints.

    Parameters

    Returns MoveVector<U128>

    a MoveVector<U128>

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

    values: an array of numbers of type number | bigint to convert to U128s

  • Factory method to generate a MoveVector of U16s from an array of numbers.

    Parameters

    • values: number[]

    Returns MoveVector<U16>

    a MoveVector<U16>

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

    values: an array of numbers to convert to U16s

  • Factory method to generate a MoveVector of U256s from an array of numbers or bigints.

    Parameters

    Returns MoveVector<U256>

    a MoveVector<U256>

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

    values: an array of numbers of type number | bigint to convert to U256s

  • Factory method to generate a MoveVector of U32s from an array of numbers.

    Parameters

    • values: number[]

    Returns MoveVector<U32>

    a MoveVector<U32>

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

    values: an array of numbers to convert to U32s

  • Factory method to generate a MoveVector of U64s from an array of numbers or bigints.

    Parameters

    Returns MoveVector<U64>

    a MoveVector<U64>

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

    values: an array of numbers of type number | bigint to convert to U64s

  • Factory method to generate a MoveVector of U8s from an array of numbers.

    Parameters

    Returns MoveVector<U8>

    a MoveVector<U8>

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

    values: an array of numbers to convert to U8s