Skip to content
Algorand Developer Portal

Constants Reference

← Back to Common Utilities

This example displays all the protocol constants available in the common package. These constants define limits, sizes, and separators used throughout Algorand.

  • No LocalNet required

From the repository root:

Terminal window
cd examples
npm run example common/04-constants.ts

View source on GitHub

04-constants.ts
/**
* Example: Constants Reference
*
* This example displays all the protocol constants available in the common package.
* These constants define limits, sizes, and separators used throughout Algorand.
*
* Prerequisites:
* - No LocalNet required
*/
import {
// Address constants
ADDRESS_LENGTH,
BOOL_FALSE_BYTE,
BOOL_TRUE_BYTE,
CHECKSUM_BYTE_LENGTH,
EMPTY_SIGNATURE,
// Cryptographic constants
HASH_BYTES_LENGTH,
// Encoding constants
LENGTH_ENCODE_BYTE_SIZE,
MAX_ACCOUNT_REFERENCES,
MAX_APP_ARGS,
MAX_APP_REFERENCES,
MAX_ARGS_SIZE,
MAX_ASSET_DECIMALS,
// Asset configuration limits
MAX_ASSET_NAME_LENGTH,
MAX_ASSET_REFERENCES,
MAX_ASSET_UNIT_NAME_LENGTH,
MAX_ASSET_URL_LENGTH,
MAX_BOX_REFERENCES,
// Application program constants
MAX_EXTRA_PROGRAM_PAGES,
// Application state schema limits
MAX_GLOBAL_STATE_KEYS,
MAX_LOCAL_STATE_KEYS,
// Application reference limits
MAX_OVERALL_REFERENCES,
MAX_TRANSACTION_GROUP_SIZE,
PROGRAM_PAGE_SIZE,
PUBLIC_KEY_BYTE_LENGTH,
SIGNATURE_BYTE_LENGTH,
// Transaction-related constants
TRANSACTION_DOMAIN_SEPARATOR,
TRANSACTION_GROUP_DOMAIN_SEPARATOR,
TRANSACTION_ID_LENGTH,
} from '@algorandfoundation/algokit-utils/common';
import { formatBytes, printHeader, printInfo, printStep, printSuccess } from '../shared/utils.js';
function main() {
printHeader('Constants Reference Example');
// Step 1: Transaction-Related Constants
printStep(1, 'Transaction-Related Constants');
printInfo(`TRANSACTION_DOMAIN_SEPARATOR: "${TRANSACTION_DOMAIN_SEPARATOR}"`);
printInfo(` Used as prefix when hashing transactions for signing`);
printInfo(`TRANSACTION_GROUP_DOMAIN_SEPARATOR: "${TRANSACTION_GROUP_DOMAIN_SEPARATOR}"`);
printInfo(` Used as prefix when hashing transaction groups`);
printInfo(`MAX_TRANSACTION_GROUP_SIZE: ${MAX_TRANSACTION_GROUP_SIZE}`);
printInfo(` Maximum number of transactions in an atomic group`);
// Step 2: Cryptographic Constants
printStep(2, 'Cryptographic Constants');
printInfo(`HASH_BYTES_LENGTH: ${HASH_BYTES_LENGTH} bytes`);
printInfo(` Length of SHA512/256 hash output`);
printInfo(`PUBLIC_KEY_BYTE_LENGTH: ${PUBLIC_KEY_BYTE_LENGTH} bytes`);
printInfo(` Length of Ed25519 public key`);
printInfo(`SIGNATURE_BYTE_LENGTH: ${SIGNATURE_BYTE_LENGTH} bytes`);
printInfo(` Length of Ed25519 signature`);
printInfo(`EMPTY_SIGNATURE: ${formatBytes(EMPTY_SIGNATURE)}`);
printInfo(` Pre-allocated empty signature (${EMPTY_SIGNATURE.length} zero bytes)`);
// Step 3: Address Constants
printStep(3, 'Address Constants');
printInfo(`ADDRESS_LENGTH: ${ADDRESS_LENGTH} characters`);
printInfo(` Length of base32-encoded Algorand address string`);
printInfo(`CHECKSUM_BYTE_LENGTH: ${CHECKSUM_BYTE_LENGTH} bytes`);
printInfo(` Length of address checksum (last 4 bytes of SHA512/256 hash)`);
printInfo(`TRANSACTION_ID_LENGTH: ${TRANSACTION_ID_LENGTH} characters`);
printInfo(` Length of base32-encoded transaction ID string`);
// Step 4: Application Program Constants
printStep(4, 'Application Program Constants');
printInfo(`MAX_EXTRA_PROGRAM_PAGES: ${MAX_EXTRA_PROGRAM_PAGES}`);
printInfo(` Maximum additional pages beyond the base page`);
printInfo(`PROGRAM_PAGE_SIZE: ${PROGRAM_PAGE_SIZE} bytes`);
printInfo(` Size of each program page (approval + clear combined)`);
printInfo(
` Total max program size: ${PROGRAM_PAGE_SIZE * (1 + MAX_EXTRA_PROGRAM_PAGES)} bytes (${1 + MAX_EXTRA_PROGRAM_PAGES} pages)`,
);
printInfo(`MAX_APP_ARGS: ${MAX_APP_ARGS}`);
printInfo(` Maximum number of application call arguments`);
printInfo(`MAX_ARGS_SIZE: ${MAX_ARGS_SIZE} bytes`);
printInfo(` Maximum total size of all application arguments combined`);
// Step 5: Application Reference Limits
printStep(5, 'Application Reference Limits');
printInfo(`MAX_OVERALL_REFERENCES: ${MAX_OVERALL_REFERENCES}`);
printInfo(` Maximum total foreign references (accounts + apps + assets + boxes)`);
printInfo(`MAX_ACCOUNT_REFERENCES: ${MAX_ACCOUNT_REFERENCES}`);
printInfo(` Maximum foreign accounts in a single app call`);
printInfo(`MAX_APP_REFERENCES: ${MAX_APP_REFERENCES}`);
printInfo(` Maximum foreign applications in a single app call`);
printInfo(`MAX_ASSET_REFERENCES: ${MAX_ASSET_REFERENCES}`);
printInfo(` Maximum foreign assets in a single app call`);
printInfo(`MAX_BOX_REFERENCES: ${MAX_BOX_REFERENCES}`);
printInfo(` Maximum box references in a single app call`);
// Step 6: Application State Schema Limits
printStep(6, 'Application State Schema Limits');
printInfo(`MAX_GLOBAL_STATE_KEYS: ${MAX_GLOBAL_STATE_KEYS}`);
printInfo(` Maximum key-value pairs in application global state`);
printInfo(`MAX_LOCAL_STATE_KEYS: ${MAX_LOCAL_STATE_KEYS}`);
printInfo(` Maximum key-value pairs in per-account local state`);
// Step 7: Asset Configuration Limits
printStep(7, 'Asset Configuration Limits');
printInfo(`MAX_ASSET_NAME_LENGTH: ${MAX_ASSET_NAME_LENGTH} bytes`);
printInfo(` Maximum length of asset name`);
printInfo(`MAX_ASSET_UNIT_NAME_LENGTH: ${MAX_ASSET_UNIT_NAME_LENGTH} bytes`);
printInfo(` Maximum length of asset unit name (ticker symbol)`);
printInfo(`MAX_ASSET_URL_LENGTH: ${MAX_ASSET_URL_LENGTH} bytes`);
printInfo(` Maximum length of asset URL`);
printInfo(`MAX_ASSET_DECIMALS: ${MAX_ASSET_DECIMALS}`);
printInfo(` Maximum decimal places for asset divisibility`);
// Step 8: Encoding Constants
printStep(8, 'Encoding Constants');
printInfo(`LENGTH_ENCODE_BYTE_SIZE: ${LENGTH_ENCODE_BYTE_SIZE} bytes`);
printInfo(` Size of length prefix in ABI encoding`);
printInfo(
`BOOL_TRUE_BYTE: 0x${BOOL_TRUE_BYTE.toString(16).toUpperCase().padStart(2, '0')} (${BOOL_TRUE_BYTE})`,
);
printInfo(` Byte value representing boolean true in ABI encoding`);
printInfo(
`BOOL_FALSE_BYTE: 0x${BOOL_FALSE_BYTE.toString(16).toUpperCase().padStart(2, '0')} (${BOOL_FALSE_BYTE})`,
);
printInfo(` Byte value representing boolean false in ABI encoding`);
// Step 9: Quick Reference Summary
printStep(9, 'Quick Reference Summary');
printInfo('Transaction Limits:');
printInfo(` - Max group size: ${MAX_TRANSACTION_GROUP_SIZE} transactions`);
printInfo(` - Transaction ID: ${TRANSACTION_ID_LENGTH} chars`);
printInfo('\nCryptographic Sizes:');
printInfo(
` - Hash: ${HASH_BYTES_LENGTH} bytes | Public Key: ${PUBLIC_KEY_BYTE_LENGTH} bytes | Signature: ${SIGNATURE_BYTE_LENGTH} bytes`,
);
printInfo('\nAddress Format:');
printInfo(` - String: ${ADDRESS_LENGTH} chars | Checksum: ${CHECKSUM_BYTE_LENGTH} bytes`);
printInfo('\nApplication Limits:');
printInfo(
` - Program: ${PROGRAM_PAGE_SIZE * (1 + MAX_EXTRA_PROGRAM_PAGES)} bytes max (${1 + MAX_EXTRA_PROGRAM_PAGES} pages x ${PROGRAM_PAGE_SIZE})`,
);
printInfo(` - Args: ${MAX_APP_ARGS} max, ${MAX_ARGS_SIZE} bytes total`);
printInfo(
` - References: ${MAX_OVERALL_REFERENCES} total (${MAX_ACCOUNT_REFERENCES} accounts, ${MAX_APP_REFERENCES} apps, ${MAX_ASSET_REFERENCES} assets, ${MAX_BOX_REFERENCES} boxes)`,
);
printInfo(` - State: ${MAX_GLOBAL_STATE_KEYS} global keys, ${MAX_LOCAL_STATE_KEYS} local keys`);
printInfo('\nAsset Limits:');
printInfo(
` - Name: ${MAX_ASSET_NAME_LENGTH} bytes | Unit: ${MAX_ASSET_UNIT_NAME_LENGTH} bytes | URL: ${MAX_ASSET_URL_LENGTH} bytes | Decimals: ${MAX_ASSET_DECIMALS} max`,
);
printSuccess('Constants Reference example completed successfully!');
}
main();