Algorand TypeScript
    Preparing search index...

    Type Alias Box<TValue>

    A Box proxy

    type Box<TValue> = {
        exists: boolean;
        key: bytes;
        length: uint64;
        value: TValue;
        create(options?: { size?: uint64 }): boolean;
        delete(): boolean;
        get(options: { default: TValue }): TValue;
        maybe(): readonly [TValue, boolean];
    }

    Type Parameters

    • TValue

      The type of the data stored in the box.

    Index

    Properties

    exists: boolean

    Get a boolean indicating if the box exists or not

    key: bytes

    Get the key used by this box proxy

    length: uint64

    Returns the length of the box, or error if the box does not exist

    value: TValue

    Get or set the value stored in the box

    Get will error if the box does not exist

    Methods

    • Create the box for this proxy with a bzero value.

      • If options.size is specified, the box will be created with that length
      • Otherwise the box will be created with arc4EncodedLength(TValue). Errors if the encoded length is not fixed

      No op if the box already exists

      Parameters

      • Optionaloptions: { size?: uint64 }

      Returns boolean

      True if the box was created, false if it already existed

    • Delete the box associated with this proxy if it exists.

      Returns boolean

      True if the box existed and was deleted, else false

    • Get the value stored in the box, or return a specified default value if the box does not exist

      Parameters

      • options: { default: TValue }

        Options to specify a default value to be returned if no other value exists

      Returns TValue

      The value if the box exists, else the default value

    • Get the value stored in the box if available, and a boolean indicating if the box exists.

      If the box does not exist, the value returned at position 0 should not be relied on to have a valid value.

      Returns readonly [TValue, boolean]

      A tuple with the first item being the box value, and the second item being a boolean indicating if the box exists.