Skip to content

Client Generation

When you build a service, the CLI emits an abi.json describing its methods, types, and events. You can turn that ABI into a type-safe TypeScript client that other applications use to call your service.

The repository ships a helper, scripts/generate-client.js, which adapts the SDK’s ABI to the client generator’s format and runs @calimero-network/abi-codegen for you.

Terminal window
npx calimero-sdk build src/index.ts -o build/service.wasm

This creates build/abi.json next to build/service.wasm.

Terminal window
node scripts/generate-client.js <abi-json-path> <output-dir> [client-name]

Parameters

  • <abi-json-path> — path to your ABI (default build/abi.json).
  • <output-dir> — where generated files are written (default build/generated).
  • [client-name] — optional class name for the generated client (passed through as --client-name).

Example

Terminal window
node scripts/generate-client.js build/abi.json src/generated CounterClient

There is also a thin shell wrapper, scripts/generate-client.sh, that forwards the same arguments.

The generated file contains the client class plus the TypeScript types for your service. It talks to a node through the Calimero client library — roughly:

import { CounterClient } from './generated/CounterClient';
// ...construct/connect a client per your generator + client-library version...
const client = new CounterClient(/* app/context wiring */);
await client.increment();
const count = await client.getCount();
{
"scripts": {
"build": "calimero-sdk build src/index.ts -o build/service.wasm",
"generate:client": "node scripts/generate-client.js build/abi.json src/generated",
"build:all": "npm run build && npm run generate:client"
}
}

Make sure the generated directory is included in your tsconfig.json include globs.

  • “ABI file not found” — build the service first and check the path (ls build/abi.json).
  • Client generation failed — verify abi.json is valid JSON and that npx can reach @calimero-network/abi-codegen; re-run with more output.
  • Type errors in generated code — ensure a compatible @calimero-network/calimero-client version and that all service types are well-defined.