cosmwasm-typescript-gen

raw JSON →
0.3.9 verified Fri May 01 auth: no javascript renamed

A CLI tool and library for generating TypeScript types, message composers, and React query hooks from CosmWasm smart contract JSON schemas. Version 0.3.9 is an older release; the project has been renamed to @cosmwasm/ts-codegen (current v0.35.x) with breaking changes in plugin names and React Query defaults. It provides a code-first approach for Cosmos ecosystem dApp development, generating fully typed client-side code from Rust contract schemas. Compared to manual type definitions, it automates type safety and reduces boilerplate for CosmWasm frontends.

error Error: Cannot find module 'cosmwasm-typescript-gen'
cause Global install mismatch or not using npx.
fix
Use npx cosmwasm-typescript-gen generate ... or install locally: npm install --save-dev cosmwasm-typescript-gen@0.3.9
error Schema files not found in directory ./schema
cause The --schema path must point to a folder containing valid JSON schema files (usually generated by 'cargo schema').
fix
Verify the schema directory exists and contains .json files. Ensure you've run 'cargo schema' in your contract project.
error TypeError: Class extends value undefined is not a constructor or null
cause Missing or mismatched CosmJS dependencies in your project when using generated message composers.
fix
Install required CosmJS packages: npm install @cosmjs/stargate @cosmjs/cosmwasm-stargate
breaking Renamed to @cosmwasm/ts-codegen: cosmwasm-typescript-gen v0.3.9 is no longer maintained and will not receive updates.
fix Migrate to @cosmwasm/ts-codegen (npm install --save-dev @cosmwasm/ts-codegen). Update command usage accordingly.
breaking MessageComposer renamed to MsgComposer: In @cosmwasm/ts-codegen v0.35, the generated class name changed from <ContractName>MessageComposer to <ContractName>MsgComposer.
fix Update any imports referencing MessageComposer to MsgComposer.
breaking React Query defaults to v4: ts-codegen now generates React Query v4 hooks by default. Existing v3 code will break.
fix Pass --reactQueryVersion=3 flag during generation if using React Query v3, or update your React Query to v4.
gotcha Requires JSON schema output from Rust contracts: The tool only works if you have run 'cargo schema' in your CosmWasm contract project first.
fix Ensure your Rust contract generates JSON schemas via cosmwasm-schema. Run 'cargo schema' in the contract directory before using this tool.
gotcha Generated code depends on cosmjs packages: The types use CosmJS types (e.g., Coin, MsgExecuteContract). Your project must have @cosmjs/stargate and @cosmjs/cosmwasm-stargate installed.
fix npm install @cosmjs/stargate @cosmjs/cosmwasm-stargate
npm install cosmwasm-typescript-gen
yarn add cosmwasm-typescript-gen
pnpm add cosmwasm-typescript-gen

Generates TypeScript client code from a CosmWasm contract schema, including types, message builders, and optionally React Query or Recoil hooks.

npx cosmwasm-typescript-gen@0.3.9 generate --schema ./schema --out ./src --name MyContract

# Or for newer projects (recommended):
# npx @cosmwasm/ts-codegen generate --schema ./schema --out ./src --name MyContract --reactQueryVersion=4