cosmscript

raw JSON →
0.0.18 verified Fri May 01 auth: no javascript

A TypeScript transpiler for CosmWasm smart contracts that generates type-safe client libraries from Protobuf schemas. Current stable version is 0.0.18, with irregular releases. It differentiates from other code generators by focusing on end-to-end TypeScript support and integration with the Cosmos ecosystem. Note: The version is very early (0.0.18) and the package may have limited stability.

error Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/cosmscript/index.js from /path/to/your/file.js not supported.
cause Using CommonJS require on an ESM-only package.
fix
Change to import statement or use dynamic import().
error Cannot find module '@cosmjs/cosmwasm-stargate'
cause Missing required peer dependency.
fix
Install @cosmjs/cosmwasm-stargate via npm.
error TypeError: cosmscript.generate is not a function
cause Using default import instead of named import for generate.
fix
Use import { generate } from 'cosmscript'.
gotcha cosmscript version 0.0.18 is very early; API may break without notice.
fix Pin to exact version and test upgrades carefully.
breaking Package is ESM-only; does not support CommonJS require.
fix Use import syntax and ensure your project is configured for ESM (e.g., type: 'module' in package.json).
gotcha Generated code depends on @cosmjs/cosmwasm-stargate and @cosmjs/proto-signing; these must be installed separately.
fix Run npm install @cosmjs/cosmwasm-stargate @cosmjs/proto-signing in your project.
npm install cosmscript
yarn add cosmscript
pnpm add cosmscript

Install cosmscript globally, generate client code from a CosmWasm schema, then use the generated client to query a contract.

// Install cosmscript globally
// npm install -g cosmscript

// Generate TypeScript types from schema
// cosmscript generate \
//   --schema ./schema \
//   --out ./src \
//   --name MyContract

// Example using generated code:
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate';
import { MyContractQueryClient } from './src/MyContract.client';

const client = await CosmWasmClient.connect('https://rpc.cosmos.network');
const queryClient = new MyContractQueryClient(client, 'cosmos1...');
const config = await queryClient.config();
console.log(config);