Skip to content

Add minimal mode to generate lightweight clients for method calls only #149

Open
@drichar

Description

@drichar

Problem

The current ARC-56 client generator creates comprehensive TypeScript clients that include functionality for deploying, creating, updating, and deleting applications, along with method calls. However, in many use cases (like SDKs that interact with existing deployed contracts), only the method call functionality is needed.

The generated clients include large amounts of code and type definitions that aren't necessary for these simpler use cases, resulting in:

  1. Unnecessarily large file sizes (several hundred KB for complex contracts)
  2. Increased bundle sizes when these clients are included in applications
  3. Slower build times due to TypeScript processing large files

Currently, I'm using a post-processing script to remove unnecessary parts of the ARC-56 JSON files before generating clients, which achieves the same result but is a workaround rather than a proper solution.

Solution

Add a minimal mode to the client generator that creates lightweight clients focused solely on making method calls to existing applications.

Proposal

Enhance the client generator with a "mode" option that supports different levels of client generation:

  1. full (default): Generate the complete client with all functionality
  2. minimal: Generate a client that only includes ABI method calls to an existing application

For the CLI, this could be implemented as:

npx --yes  @algorandfoundation/algokit-client-generator generate -a ./application.json -m minimal -o ./client.generated.ts

For the programmatic API:

generate(appJson, {
  mode: 'minimal',
  // Other options...
})

In minimal mode, the generator should:

  • Retain only the error messages in the sourceInfo entries (removing entries without errorMessage properties)
  • Exclude the top-level source property containing bytecode
  • Include only the necessary types and methods for making ABI calls to existing contracts
  • Exclude deployment, creation, update, and deletion functionality

This approach would significantly reduce the size of generated clients while preserving the essential error handling information needed to provide meaningful feedback to users when method assertions fail.

Pros and Cons

Pros:

  • Significantly smaller generated files for simpler use cases (as much as 75% file size reduction)
  • Faster build times and smaller bundle sizes
  • Cleaner, more focused code for specific use cases
  • Maintains the ARC-56 JSON files as the single source of truth
  • More maintainable than post-processing scripts

Cons:

  • Additional complexity in the generator code
  • Need to maintain backward compatibility
  • May require refactoring of the generator's internal structure (?)

Dependencies

This feature would require:

  1. Updates to the generator's CLI interface
  2. Updates to the algokit-cli generate command
  3. Modifications to the code generation logic to support conditional inclusion of components
  4. Documentation updates to explain the new option
  5. Potentially new test cases to verify the different generation modes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions