Box
Algorand TypeScript / op / Box
constBox:object
Defined in: op.ts:614
Get or modify box state
Type declaration
Section titled “Type declaration”create()
Section titled “create()”create(
a,b):boolean
create a box named A, of length B. Fail if the name A is empty or B exceeds 32,768. Returns 0 if A already existed, else 1
Newly created boxes are filled with 0 bytes. box_create will fail if the referenced box already exists with a different size. Otherwise, existing boxes are unchanged by box_create.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”boolean
Native TEAL opcode: box_create
Min AVM version: 8
delete()
Section titled “delete()”delete(
a):boolean
delete box named A if it exists. Return 1 if A existed, 0 otherwise
Parameters
Section titled “Parameters”Returns
Section titled “Returns”boolean
Native TEAL opcode: box_del
Min AVM version: 8
extract()
Section titled “extract()”extract(
a,b,c):bytes
read C bytes from box A, starting at offset B. Fail if A does not exist, or the byte range is outside A’s size.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Native TEAL opcode: box_extract
Min AVM version: 8
get(
a): readonly [bytes,boolean]
X is the contents of box A if A exists, else ”. Y is 1 if A exists, else 0.
For boxes that exceed 4,096 bytes, consider box_create, box_extract, and box_replace
Parameters
Section titled “Parameters”Returns
Section titled “Returns”readonly [bytes, boolean]
Native TEAL opcode: box_get
Min AVM version: 8
length()
Section titled “length()”length(
a): readonly [uint64,boolean]
X is the length of box A if A exists, else 0. Y is 1 if A exists, else 0.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”readonly [uint64, boolean]
Native TEAL opcode: box_len
Min AVM version: 8
put(
a,b):void
replaces the contents of box A with byte-array B. Fails if A exists and len(B) != len(box A). Creates A if it does not exist
For boxes that exceed 4,096 bytes, consider box_create, box_extract, and box_replace
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
Native TEAL opcode: box_put
Min AVM version: 8
replace()
Section titled “replace()”replace(
a,b,c):void
write byte-array C into box A, starting at offset B. Fail if A does not exist, or the byte range is outside A’s size.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
Native TEAL opcode: box_replace
Min AVM version: 8
resize()
Section titled “resize()”resize(
a,b):void
change the size of box named A to be of length B, adding zero bytes to end or removing bytes from the end, as needed. Fail if the name A is empty, A is not an existing box, or B exceeds 32,768.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
Native TEAL opcode: box_resize
Min AVM version: 10
splice()
Section titled “splice()”splice(
a,b,c,d):void
set box A to contain its previous bytes up to index B, followed by D, followed by the original bytes of A that began at index B+C. Boxes are of constant length. If C < len(D), then len(D)-C bytes will be removed from the end. If C > len(D), zero bytes will be appended to the end to reach the box length.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
Native TEAL opcode: box_splice
Min AVM version: 10