.proto files and produce TypeScript code that’s directly compatible with CosmJS’s Registry, createProtobufRpcClient, and AminoTypes.
Choosing a Generator
| Telescope | ts-proto | protobufjs | |
|---|---|---|---|
| Approach | Full-stack Cosmos codegen | General-purpose protobuf codegen | Runtime type definitions |
| Output | Message codecs, query clients, Amino converters, registry helpers, LCD clients | Message codecs, query service clients | Encode/decode at runtime (no build step) |
| CosmJS interface | TelescopeGeneratedType | TsProtoGeneratedType / TsProto2GeneratedType | PbjsGeneratedType |
fromPartial | Yes | Yes | No (uses create) |
| Best for | Full dApp development, chain-specific libraries | Matching CosmJS’s own code style, lightweight projects | Prototyping, runtime-defined types |
| Used by | OsmoJS, Stargaze, dYdX, Stride | cosmjs-types (CosmJS itself) | Quick prototypes, dynamic schemas |
Telescope
Telescope is the most popular code generator in the Cosmos ecosystem. It produces complete TypeScript libraries that include everything needed for CosmJS integration — message codecs, query clients, Amino converters, and registry arrays.Quick Start
Telescope v2 has been published as
@hyperweb/telescope with InterchainJS as the default dependency. For CosmJS-based projects, @cosmology/telescope v1.x remains the recommended version. The CLI commands below work with both versions.This creates a new project scaffold. Place your
.proto files (or the chain’s proto files) into the ./proto directory.Using Telescope Output with CosmJS
Telescope-generated types implementTelescopeGeneratedType, which the CosmJS Registry accepts directly. A typical Telescope output includes:
- Message codecs (
MsgXxxwithencode,decode,fromPartial) - Query clients (
QueryClientImplfor gRPC-web queries) - Registry arrays (pre-built
[typeUrl, codec]pairs) - Amino converters (ready-made
AminoConverterobjects)
Chain-Specific Libraries
Many popular chains already have Telescope-generated libraries published on npm:| Chain | Package | Install |
|---|---|---|
| Osmosis | osmojs | npm install osmojs |
| Stargaze | stargazejs | npm install stargazejs |
| Juno | juno-network | npm install juno-network |
| Stride | stridejs | npm install stridejs |
| dYdX | @dydxprotocol/v4-client-js | npm install @dydxprotocol/v4-client-js |
| Injective | @injectivelabs/sdk-ts | npm install @injectivelabs/sdk-ts |
ts-proto
CosmJS itself uses ts-proto via thecosmjs-types package. It’s a lightweight, general-purpose protobuf code generator that produces clean TypeScript with no Cosmos-specific abstractions.
Setup
Installts-proto and protoc (the Protocol Buffer compiler):
protoc installed on your system.
Generating Code
ts_proto_opt options:
| Option | Recommended value | Purpose |
|---|---|---|
esModuleInterop | true | Compatibility with ES module imports |
forceLong | bigint | Use native bigint instead of the Long library |
useOptionals | messages | Make nested message fields optional |
MsgXxx and QueryClientImpl classes work directly with CosmJS’s Registry and createProtobufRpcClient.
Working with Yarn 2+
The binary./node_modules/.bin/protoc-gen-ts_proto is not easily available in Yarn 2+. Create an executable wrapper script bin/protoc-gen-ts_proto_yarn_2:
--ts_proto_yarn_2_opt instead of --ts_proto_opt in your protoc command. See the cosmjs-types repo for a full example.
protobufjs (Runtime Types)
For prototyping or when you don’t have access to.proto files, protobufjs lets you define types at runtime in pure JavaScript — no build step required:
When to Use protobufjs
- Prototyping: Quickly test a message type without setting up a codegen pipeline
- Dynamic schemas: When the proto definitions aren’t known at build time
- Plain JavaScript: When you don’t want a TypeScript build step
Next Steps
Custom Protobuf Types
Register your generated types in the CosmJS Registry.
Custom Modules
Wire generated types into a complete module integration.
Supporting New Chains
Configure CosmJS for your chain’s address prefix, gas token, and account type.