Class Arc82

Main parser class for ARC-82 Algorand URIs. Provides static methods for parsing, constructing, and querying ARC-82 compliant URIs.

Example

// Parse an ARC-82 URI
const parsed = Arc82.parse('algorand://app/123?global=Z2xvYmFsX2tleQ%3D%3D');

// Build an ARC-82 URI
const uri = Arc82.buildAppUri(123, {
global: ['Z2xvYmFsX2tleQ%3D%3D']
});

// Query blockchain data
const result = await Arc82.queryFromUri(uri, 'testnet');

Constructors

Properties

APP_PATH_PREFIX: "//app/" = '//app/'

Path prefix for application URIs

ASSET_PATH_PREFIX: "//asset/" = '//asset/'

Path prefix for asset URIs

SCHEME: "algorand" = 'algorand'

The ARC-82 URI scheme

Methods

  • Constructs an ARC-82 compliant application URI.

    Parameters

    • id: number

      The application ID to include in the URI

    • Optional params: AppQueryParams

      Optional query parameters for the application

    Returns string

    A formatted ARC-82 URI string for the application

    Throws

    When the ID is invalid or parameters are malformed

    Example

    // Simple application URI
    const uri1 = Arc82.buildAppUri(123);
    // "algorand://app/123"

    // Application URI with box query
    const uri2 = Arc82.buildAppUri(123, {
    box: ['Ym94X2tleQ%3D%3D']
    });
    // "algorand://app/123?box=Ym94X2tleQ%3D%3D"
  • Constructs an ARC-82 compliant asset URI.

    Parameters

    • id: number

      The asset ID to include in the URI

    • Optional params: AssetQueryParams

      Optional query parameters for the asset

    Returns string

    A formatted ARC-82 URI string for the asset

    Throws

    When the ID is invalid

    Example

    // Simple asset URI
    const uri1 = Arc82.buildAssetUri(456);
    // "algorand://asset/456"

    // Asset URI with multiple parameters
    const uri2 = Arc82.buildAssetUri(456, {
    total: true,
    decimals: true,
    unitname: true
    });
    // "algorand://asset/456?total&decimals&unitname"
  • Decodes a base64url encoded string to UTF-8.

    Parameters

    • base64url: string

      The base64url encoded string to decode

    Returns string

    The decoded UTF-8 string

    Throws

    When the input is invalid base64url or decoding fails

    Example

    const decoded = Arc82.decodeBase64Url('SGVsbG8gV29ybGQ');
    // "Hello World"
  • Encodes a UTF-8 string to base64url format.

    Parameters

    • str: string

      The UTF-8 string to encode

    Returns string

    The base64url encoded string

    Example

    const encoded = Arc82.encodeBase64Url('Hello World');
    // "SGVsbG8gV29ybGQ"
  • Extracts the ID from an ARC-82 URI without performing full parsing.

    Parameters

    • uri: string

      The URI string to extract the ID from

    Returns null | number

    The extracted ID or null if the URI is invalid

    Example

    const id1 = Arc82.extractId('algorand://app/123');
    // 123

    const id2 = Arc82.extractId('invalid://uri');
    // null
  • Extracts the type from an ARC-82 URI without performing full parsing.

    Parameters

    • uri: string

      The URI string to extract the type from

    Returns null | AlgorandUriType

    The extracted type (APPLICATION or ASSET) or null if invalid

    Example

    const type1 = Arc82.extractType('algorand://app/123');
    // AlgorandUriType.APPLICATION

    const type2 = Arc82.extractType('algorand://asset/456');
    // AlgorandUriType.ASSET

    const type3 = Arc82.extractType('invalid://uri');
    // null
  • Private

    Validates whether a string is in valid Algorand address format. Uses simplified validation - a robust implementation would use algosdk.

    Parameters

    • address: string

      The address string to validate

    Returns boolean

    True if the address format is valid, false otherwise

  • Validates whether a URI string is ARC-82 compliant.

    Parameters

    • uri: string

      The URI string to validate

    Returns boolean

    True if the URI is valid ARC-82 format, false otherwise

    Example

    const isValid1 = Arc82.isValidArc82Uri('algorand://app/123');
    // true

    const isValid2 = Arc82.isValidArc82Uri('http://example.com');
    // false
  • Private

    Validates whether a string is properly base64url encoded.

    Parameters

    • str: string

      The string to validate

    Returns boolean

    True if the string is valid base64url, false otherwise

  • Parses an ARC-82 compliant URI string.

    Parameters

    • uri: string

      The URI string to parse

    Returns ParsedAlgorandUri

    The parsed URI object containing type, ID, and parameters

    Throws

    When the URI is invalid or malformed

    Example

    const parsed = Arc82.parse('algorand://app/123?box=Ym94X2tleQ%3D%3D');
    console.log(parsed.type); // AlgorandUriType.APPLICATION
    console.log(parsed.id); // 123
    console.log(parsed.appParams?.box); // ['Ym94X2tleQ%3D%3D']
  • Private

    Parses application-specific query parameters from URL search parameters.

    Parameters

    • searchParams: URLSearchParams

      The URLSearchParams object containing query parameters

    • uri: string

      The original URI string for error reporting

    Returns AppQueryParams

    Parsed application query parameters

    Throws

    When parameters are invalid or malformed

  • Private

    Parses asset-specific query parameters from URL search parameters.

    Parameters

    • searchParams: URLSearchParams

      The URLSearchParams object containing query parameters

    • uri: string

      The original URI string for error reporting

    Returns AssetQueryParams

    Parsed asset query parameters

  • Queries application data from the Algorand blockchain based on a parsed ARC-82 URI.

    This method fetches application information and any requested storage data from the blockchain. It supports querying box storage, global state, local state, and TEAL programs.

    Parameters

    • parsedUri: ParsedAlgorandUri

      The parsed ARC-82 URI for an application

    • network: Network

      The Algorand network to query (mainnet, testnet, localnet)

    Returns Promise<AppQueryResult>

    A promise that resolves to application query results

    Throws

    When the URI is not for an application or querying fails

    Example

    const uri = 'algorand://app/123?global=Z2xvYmFsX2tleQ%3D%3D&box=Ym94X2tleQ%3D%3D';
    const parsed = Arc82.parse(uri);
    const result = await Arc82.queryApplication(parsed, 'testnet');

    if (result.success) {
    console.log('Application exists:', result.exists);
    console.log('Global state:', result.global);
    console.log('Box storage:', result.boxes);
    }
  • Queries asset data from the Algorand blockchain based on a parsed ARC-82 URI.

    This method fetches asset information and any requested parameter data from the blockchain. It supports querying all asset parameters including total supply, decimals, frozen status, names, URLs, and administrative addresses.

    Parameters

    • parsedUri: ParsedAlgorandUri

      The parsed ARC-82 URI for an asset

    • network: Network

      The Algorand network to query (mainnet, testnet, localnet)

    Returns Promise<AssetQueryResult>

    A promise that resolves to asset query results

    Throws

    When the URI is not for an asset or querying fails

    Example

    const uri = 'algorand://asset/456?total&decimals&unitname';
    const parsed = Arc82.parse(uri);
    const result = await Arc82.queryAsset(parsed, 'testnet');

    if (result.success && result.exists) {
    console.log('Total supply:', result.parameters.total);
    console.log('Decimals:', result.parameters.decimals);
    console.log('Unit name:', result.parameters.unitname);
    }
  • Queries blockchain data directly from an ARC-82 URI string.

    This is a convenience method that combines URI parsing and blockchain querying in a single operation. It automatically determines whether the URI is for an application or asset and calls the appropriate query method.

    Parameters

    • uri: string

      The ARC-82 URI string to parse and query

    • network: Network

      The Algorand network to query (mainnet, testnet, localnet)

    Returns Promise<AppQueryResult | AssetQueryResult>

    A promise that resolves to query results (either application or asset data)

    Throws

    When the URI is invalid

    Throws

    When blockchain querying fails

    Example

    // Query application data
    const appResult = await Arc82.queryFromUri(
    'algorand://app/123?global=Z2xvYmFsX2tleQ%3D%3D',
    'testnet'
    );

    // Query asset data
    const assetResult = await Arc82.queryFromUri(
    'algorand://asset/456?total&unitname',
    'testnet'
    );