Description
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:
- Unnecessarily large file sizes (several hundred KB for complex contracts)
- Increased bundle sizes when these clients are included in applications
- 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:
- full (default): Generate the complete client with all functionality
- 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 withouterrorMessage
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:
- Updates to the generator's CLI interface
- Updates to the algokit-cli
generate
command - Modifications to the code generation logic to support conditional inclusion of components
- Documentation updates to explain the new option
- Potentially new test cases to verify the different generation modes