@algorandfoundation/algokit-client-generator

中文文档
6.0.2发布于 2026/11/06MITTypeScriptESM + CJS构建来源已验证近 30 天下载 4262

Generates a TypeScript client for interacting with, and deploying ARC-0032 smart contracts on the Algorand Blockchain.

原始使用文档
文档目录11 节
  1. Usage
  2. Prerequisites
  3. Migration
  4. Use
  5. Code Examples
  6. Contributing
  7. Initial setup
  8. Subsequently
  9. Building examples
  10. Continuous Integration / Continuous Deployment (CI/CD)
  11. Approval tests

AlgoKit TypeScript client generator (algokit-client-generator-ts)

This project generates a type-safe smart contract client in TypeScript for the Algorand Blockchain that wraps the application client in AlgoKit Utils and tailors it to a specific smart contract. It does this by reading an ARC-56 or ARC-32 application spec file and generating a client which exposes methods for each ABI method in the target smart contract, along with helpers to create, update, and delete the application.

Usage

Prerequisites

To be able to consume the generated file you need to include it in a TypeScript project that has (at least) the following package installed:

npm install @algorandfoundation/algokit-utils@^9.0.0

Note: version 6 of the generator requires @algorandfoundation/algokit-utils@^9.0.0 (with algosdk v3); it is not compatible with AlgoKit Utils v10, which decoupled from algosdk.

Migration

If you're migrating your project from an older generated typed client to v4, please refer to the v4 migration guide.

Use

The cli can be used to generate a client via the following command.

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

CLI Options

The CLI supports the following options:

  • -a, --application <path> (required): Specifies the path to the ARC-56 or ARC-32 application.json file
  • -o, --output <path> (required): Specifies the output file path for the generated TypeScript client
  • --pn, --preserve-names: Preserve names from the application.json spec instead of sanitizing them to camelCase
  • -m, --mode <mode>: Generate client in specified mode (default: full)
    • full: Generates a complete client with factory, deployment capabilities and all features
    • minimal: Generates a lightweight client without factory or deployment capabilities, resulting in a smaller output

CLI Examples

Generate a full client (default):

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

Generate a minimal client:

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

Generation Modes

The generator supports two modes:

Full Mode (default):

  • Includes factory class for creating and deploying smart contracts
  • Includes deployment types and methods
  • Includes all deployment-related metadata (source code, bytecode, template variables)
  • Includes client class for interacting with already deployed contracts
  • Best for development, deployment and interaction workflows or where output size is less important

Minimal Mode:

  • Excludes factory class and deployment capabilities
  • Excludes deployment-related metadata to reduce output size
  • Only includes client class for interacting with already deployed contracts
  • Best for scenarios that only need to interact with existing contracts

Programmatic API

Alternatively, a client can be generated from code by invoking the generate function paired with either writeDocumentPartsToString or writeDocumentPartsToStream depending on your needs. We also expose helpers to optionally load and validate an application.json file.

import fs from 'fs'
import {
  writeDocumentPartsToStream,
  writeDocumentPartsToString,
  generate,
  loadApplicationJson,
  validateApplicationJson,
} from '@algorandfoundation/algokit-client-generator'
import appJson from './application.json'

const appJsonFromFile = loadApplicationJson('./application.json')
const appJsonFromObject = validateApplicationJson(appJson)

const fileStream = fs.createWriteStream('./client.ts', {
  flags: 'w',
})
writeDocumentPartsToStream(generate(appJsonFromFile), fileStream)

// Generate a full client (default)
const clientAsString = writeDocumentPartsToString(generate(appJsonFromObject))

// Generate a minimal client
const minimalClientAsString = writeDocumentPartsToString(generate(appJsonFromObject, { mode: 'minimal' }))

For details on how to use the generated client see the more detailed usage docs

Code Examples

There are a range of examples that you can look at to see a source smart contract (e.g. {contract.py}), the generated client (client.ts) and some tests that demonstrate how you can use the client (client.spec.ts).

Contributing

If you want to contribute to this project the following information will be helpful.

Initial setup

  1. Clone this repository locally

  2. Install pre-requisites:

    • Install AlgoKit - Link: Ensure you can execute algokit --version.
    • Bootstrap your local environment; run algokit bootstrap all within this folder, which will:
      • Install Poetry - Link: The minimum required version is 1.2. Ensure you can execute poetry -V and get 1.2+
      • Run poetry install in the root directory, which will set up a .venv folder with a Python virtual environment and also install all Python dependencies
      • Run pnpm install
  3. Open the project and start debugging / developing via:

    • VS Code
      1. Open the repository root in VS Code
      2. Install recommended extensions
      3. Run tests via test explorer
    • IDEA (e.g. PyCharm)
      1. Open the repository root in the IDE
      2. It should automatically detect it's a Poetry project and set up a Python interpreter and virtual environment.
      3. Run tests
    • Other
      1. Open the repository root in your text editor of choice
      2. Run pnpm run test

Subsequently

  1. If you update to the latest source code and there are new dependencies you will need to run algokit bootstrap all again
  2. Follow step 3 above

Building examples

In the examples folder there is a series of example contracts along with their generated client. These contracts are built using Algorand Python.

If you want to make changes to any of the smart contract examples and re-generate the ARC-0032 application.json files then change the corresponding examples/{contract}/{contract}.py file and then run:

poetry run python -m examples

Or in Visual Studio Code you can use the default build task (Ctrl+Shift+B).

To regenerate the generated clients run pnpm run update-approvals.

Continuous Integration / Continuous Deployment (CI/CD)

This project uses GitHub Actions to define CI/CD workflows, which are located in the .github/workflows folder.

Approval tests

Making any changes to the generated code will result in the approval tests failing. The approval tests work by generating a version of client and outputting it to ./examples/APP_NAME/client.generated.ts then comparing to the approved version ./examples/APP_NAME/client.ts. If you make a change and break the approval tests, you will need to update the approved version by overwriting it with the generated version. You can run pnpm run update-approvals to update all approved clients in one go.

版本与发布记录

@algorandfoundation/algokit-client-generator 共发布 145 个版本,首次发布于 2023/05/17;过去 12 个月发布了 19 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
6.0.2latest2026/11/061 天前
6.0.2-beta.3main2026/11/061 天前
6.0.2-beta.22026/10/0929 天前
7.0.0-beta.42026/05/205 个月前
7.0.0-beta.32026/04/136 个月前
7.0.0-beta.22026/04/136 个月前

其他发布通道:alpha → 7.0.0-alpha.9,main → 6.0.2-beta.3。

关于 @algorandfoundation/algokit-client-generator 的常见问题

@algorandfoundation/algokit-client-generator 是什么?

Generates a TypeScript client for interacting with, and deploying ARC-0032 smart contracts on the Algorand Blockchain.

如何安装 @algorandfoundation/algokit-client-generator?

在项目目录运行 npm install @algorandfoundation/algokit-client-generator,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:algosdk(^3.2.0)、@algorandfoundation/algokit-utils(^9.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。它还提供命令行工具 algokitgen、algokit-client-generator,可以用 npx algokitgen 直接运行。

@algorandfoundation/algokit-client-generator 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@algorandfoundation/algokit-client-generator 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@algorandfoundation/algokit-client-generator 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@algorandfoundation/algokit-client-generator 可以商用吗?

@algorandfoundation/algokit-client-generator 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@algorandfoundation/algokit-client-generator 的下载量有多少?

根据 npm 官方下载统计,@algorandfoundation/algokit-client-generator 在 2026/10/06 – 2026/11/04 这 30 天内被下载 4,262 次,日均约 142 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@algorandfoundation/algokit-client-generator 还在维护吗?

最新版本 6.0.2 发布于 2026/11/06(1 天前);至今共发布 145 个版本,其中过去 12 个月发布了 19 个;首次发布于 2023/05/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。