ARC4 Types
These types are available under the arc4 namespace. Refer to the ARC4 specification for more details on the spec.
Test execution context provides _value generators_ for ARC4 types. To access their _value generators_, use `{context_instance}.any.arc4` property. See more examples below.
For all `arc4` types, with or without a respective _value generator_, instantiation can be performed directly. If you have a suggestion for a new _value generator_ implementation, please open an issue in the [`algorand-typescript-testing`](https://github.com/algorandfoundation/algorand-typescript-testing) repository or contribute by following the [contribution guide](https://github.com/algorandfoundation/algorand-typescript-testing/blob/main/CONTRIBUTING.md).
import { arc4 } from '@algorandfoundation/algorand-typescript'
import { TestExecutionContext } from '@algorandfoundation/algorand-typescript-testing'
// Create the context manager for snippets below
const ctx = new TestExecutionContext()
Unsigned Integers
Section titled “Unsigned Integers”// Integer types
const uint8Value = new arc4.Uint8(255)
const uint16Value = new arc4.Uint16(65535)
const uint32Value = new arc4.Uint32(4294967295)
const uint64Value = new arc4.Uint64(18446744073709551615n)
// Generate a random unsigned arc4 integer with default range
const uint8 = ctx.any.arc4.uint8()
const uint16 = ctx.any.arc4.uint16()
const uint32 = ctx.any.arc4.uint32()
const uint64 = ctx.any.arc4.uint64()
const biguint128 = ctx.any.arc4.uint128()
const biguint256 = ctx.any.arc4.uint256()
const biguint512 = ctx.any.arc4.uint512()
// Generate a random unsigned arc4 integer with specified range
const uint8Custom = ctx.any.arc4.uint8(10, 100)
const uint16Custom = ctx.any.arc4.uint16(1000, 5000)
const uint32Custom = ctx.any.arc4.uint32(100000, 1000000)
const uint64Custom = ctx.any.arc4.uint64(1000000000, 10000000000)
const biguint128Custom = ctx.any.arc4.uint128(1000000000000000, 10000000000000000n)
const biguint256Custom = ctx.any.arc4.uint256(1000000000000000000000000n, 10000000000000000000000000n)
const biguint512Custom = ctx.any.arc4.uint512(10000000000000000000000000000000000n, 10000000000000000000000000000000000n)
Address
Section titled “Address”// Address type
const addressValue = new arc4.Address('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ')
// Generate a random address
const randomAddress = ctx.any.arc4.address()
// Access native underlying type
const native = randomAddress.native
Dynamic Bytes
Section titled “Dynamic Bytes”// Dynamic byte string
const bytesValue = new arc4.DynamicBytes('Hello, Algorand!')
// Generate random dynamic bytes
const randomDynamicBytes = ctx.any.arc4.dynamicBytes(123) // n is the number of bits in the arc4 dynamic bytes
String
Section titled “String”// UTF-8 encoded string
const stringValue = new arc4.Str('Hello, Algorand!')
// Generate random string
const randomString = ctx.any.arc4.str(12) // n is the number of bits in the arc4 string
// Test cleanup
ctx.reset()