Telescope
Types

Types

Telescope generates TypeScript types from Protocol Buffer definitions for easy integration with TypeScript projects. This page documents the key types generated by Telescope and how to use them.

Basic Types

Type CategoryDescriptionExample
Message TypesTypeScript interfaces that match the structure of Protobuf messagesMsgSend, QueryBalanceRequest
Enum TypesTypeScript enums that represent Protobuf enumerationsBondStatus, ResponseCheckTxType
Service TypesTypes for RPC service interfacesMsgClientImpl, QueryClientImpl
Registry TypesTypes for registering and managing message typesGeneratedType, Registry

Message Types

For each Protobuf message, Telescope generates several types and helper functions:

Generated ItemDescriptionExample
InterfaceTypeScript interface matching the message structureexport interface MsgSend { ... }
Constructor FunctionsFunctions to create message instancesexport const MsgSend = { encode, decode, ... }
Encoding FunctionsFunctions to serialize/deserialize messagesencode, decode, fromPartial, fromJSON

Example Message Type

// Generated interface
export interface MsgSend {
  fromAddress: string;
  toAddress: string;
  amount: Coin[];
}
 
// Generated static methods for the message
export const MsgSend = {
  encode(message: MsgSend, writer: Writer = Writer.create()): Writer { ... },
  decode(input: Reader | Uint8Array, length?: number): MsgSend { ... },
  fromJSON(object: any): MsgSend { ... },
  toJSON(message: MsgSend): unknown { ... },
  fromPartial(object: DeepPartial<MsgSend>): MsgSend { ... }
}

Any Types

Telescope handles Protobuf's Any type, which allows for dynamic typing:

export interface Any {
  typeUrl: string;
  value: Uint8Array;
}

Working with Any Types

import { Any } from "./google/protobuf/any";
import { MsgSend } from "./cosmos/bank/v1beta1/tx";
 
// Packing a message into Any
const msgSend: MsgSend = { ... };
const packedMsg = Any.pack(msgSend, "/cosmos.bank.v1beta1.MsgSend");
 
// Unpacking a message from Any (using interfaces)
const unpackedMsg = packedMsg.unpack(MsgSend);

Amino Types (for Legacy Compatibility)

For compatibility with legacy systems (like Keplr), Telescope generates Amino types:

TypeDescriptionExample
AminoMsgAmino-compatible message format for signingexport interface AminoMsgSend { ... }
AminoConverterConverts between Amino and native formatsexport const aminoConverter = { ... }

Example Amino Types

export interface AminoMsgSend {
  type: "cosmos-sdk/MsgSend";
  value: {
    from_address: string;
    to_address: string;
    amount: {
      denom: string;
      amount: string;
    }[];
  };
}
 
export const aminoConverters = {
  "/cosmos.bank.v1beta1.MsgSend": {
    aminoType: "cosmos-sdk/MsgSend",
    toAmino: (message: MsgSend): AminoMsgSend["value"] => { ... },
    fromAmino: (object: AminoMsgSend["value"]): MsgSend => { ... }
  }
}

Registry Types

Telescope generates registry types for registering message types with various client libraries:

export const registry = [
  ["/cosmos.bank.v1beta1.MsgSend", MsgSend],
  ["/cosmos.staking.v1beta1.MsgDelegate", MsgDelegate],
  // other message types...
];
 
export const load = (protoRegistry: Registry) => {
  registry.forEach(([typeUrl, type]) => {
    protoRegistry.register(typeUrl, type as GeneratedType);
  });
};

Custom Type Handling

Telescope handles special types with custom encoding/decoding:

TypeTypeScript RepresentationNotes
google.protobuf.TimestampDate or { seconds: Long; nanos: number }Configurable via options
google.protobuf.Duration{ seconds: Long; nanos: number } or stringConfigurable via options
cosmos.base.v1beta1.Coin{ denom: string; amount: string }Represents blockchain tokens
Int64/Uint64bigint or LongConfigurable via options

Client Types

Telescope generates several client types for interacting with blockchain nodes:

Client TypeDescriptionExample Usage
Query ClientFor querying blockchain statequeryClient.getBalance(...)
Tx ClientFor sending transactionstxClient.send(...)
RPC ClientFor low-level RPC callsrpcClient.abciQuery(...)
LCD ClientFor REST API callslcdClient.cosmos.bank.v1beta1.allBalances(...)

Type Helper Functions

FunctionDescriptionExample
DeepPartial<T>Creates a type with all properties of T set to optionalDeepPartial<MsgSend>
fromPartial<T>Creates an object from a partial inputMsgSend.fromPartial({...})
toJSONConverts a message to a JSON-compatible objectMsgSend.toJSON(msg)
fromJSONCreates a message from a JSON-compatible objectMsgSend.fromJSON({...})

Using Generated Types

import { MsgSend } from "./cosmos/bank/v1beta1/tx";
import { queryClient, txClient } from "./client";
 
// Create a message
const sendMsg = MsgSend.fromPartial({
  fromAddress: "cosmos1...",
  toAddress: "cosmos1...",
  amount: [{ denom: "uatom", amount: "1000000" }]
});
 
// Query the blockchain
const balance = await queryClient.cosmos.bank.v1beta1.balance({
  address: "cosmos1...",
  denom: "uatom"
});
 
// Send a transaction
const result = await txClient.signAndBroadcast(
  [sendMsg],
  { gas: "200000", amount: [{ denom: "uatom", amount: "5000" }] }
);

Advanced Type Features

FeatureDescription
Union TypesGenerated for oneOf fields in Protobuf
Nested TypesGenerated for nested message definitions
Global Interface RegistryManages type information for runtime reflection
Type InformationMetadata attached to types for runtime operations

Type Safety Considerations

  • All generated types are strongly typed for TypeScript safety
  • Optional fields are properly marked with ?
  • Arrays and repeated fields are correctly typed
  • Custom scalar types have proper handling and validation
  • Functions include proper type checking