Skip to content
This new developer portal is under construction. For complete documentation, please refer to the old developer portal.

Scratch Storage

A scratch space is a temporary storage area used to store values for later use in your program. It consists of 256 scratch slots. Scratch spaces may be uint64 or byte-array and are initialized as uint64(0).

The AVM (Algorand Virtual Machine) enables smart contracts to use scratch space for temporarily storing values during execution. Other contracts in the same atomic transaction group can read this scratch space. However, contracts can only access scratch space from earlier transactions within the same group, not from later ones.

TEAL

In TEAL, you can use the store/stores and load/loads opcodes to read and write scratch slots. Additionally, you can use gload/gloads to read scratch slots from earlier transactions in the same group.

Algorand Python

In Algorand Python, you can directly use these opcodes through the op.Scratch class. The accessed scratch slot indices or index ranges need to be declared using the scratch_slots variable during contract declaration.

1
from algopy import ARC4Contract, Bytes, UInt64, arc4, op, urange
2
3
4
class HelloWorld(ARC4Contract, scratch_slots=(1, urange(3, 20))):
5
@arc4.abimethod()
6
def hello(self) -> bool:
7
op.Scratch.store(1, UInt64(5))
8
op.Scratch.store(7, Bytes(b"Hello World"))
9
10
assert op.Scratch.load_uint64(1) == UInt64(5)
11
assert op.Scratch.load_bytes(7) == b"Hello World"
12
13
return True