Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Telescope Adapters

Adapters for telescope-generated SDKs (xplajs, osmojs, neutronjs, ...) that use protobuf RPCs instead of cosmjs's JSON API.

import { createQueryAdapter, createExecuteAdapter } from 'schemos/telescope'

Why Adapters?

cosmjs's SigningCosmWasmClient conforms to schemos's client interface directly. Telescope SDKs don't — they use protobuf-encoded Uint8Array messages and chain-specific RPC functions.

The adapter bridges this gap with three user-provided callbacks, keeping schemos chain-agnostic. See Why Callbacks for the full rationale.

createQueryAdapter

Wraps a telescope RPC query function into a CosmWasmQueryClient.

function createQueryAdapter(
  smartContractState: SmartContractStateFn,
): CosmWasmQueryClient

Parameters

ParameterTypeDescription
smartContractStateSmartContractStateFnTelescope RPC query function. All telescope SDKs export this at cosmwasm.wasm.v1.smartContractState.

See Telescope SDKs integration for usage examples.

createExecuteAdapter

Creates a full execute+query adapter from three callbacks.

function createExecuteAdapter<TExecuteResult>(
  smartContractState: SmartContractStateFn,
  signAndBroadcast: SignAndBroadcastFn<TExecuteResult>,
  encodeMsgExecuteContract: EncodeMsgExecuteContractFn,
): CosmWasmExecuteClient<TExecuteResult>

Parameters

ParameterTypeDescription
smartContractStateSmartContractStateFnTelescope RPC query function
signAndBroadcastSignAndBroadcastFnSigning client's broadcast method
encodeMsgExecuteContractEncodeMsgExecuteContractFnProtobuf encoder for MsgExecuteContract — provided from the chain's telescope package

See Telescope SDKs integration for usage examples.

Types

SmartContractStateFn

type SmartContractStateFn = (params: {
  address: string
  queryData: Uint8Array
}) => Promise<{ data: Uint8Array }>

All telescope SDKs export a function matching this signature at cosmwasm.wasm.v1.smartContractState.

SignAndBroadcastFn

type SignAndBroadcastFn<TResult = unknown> = (
  sender: string,
  messages: readonly { typeUrl: string; value: Uint8Array }[],
  fee: InterchainStdFee | 'auto',
  memo?: string,
) => Promise<TResult>

Accepts already-encoded protobuf messages. Each telescope SDK provides this via its signing client.

EncodeMsgExecuteContractFn

type EncodeMsgExecuteContractFn = (params: {
  sender: string
  contract: string
  msg: Uint8Array
  funds: readonly Coin[]
}) => Uint8Array

Encodes contract execution params to MsgExecuteContract protobuf bytes. The pattern is identical across telescope packages — only the import path changes:

// xplajs
import { MsgExecuteContract } from '@xpla/xplajs/cosmwasm/wasm/v1/tx'
 
// osmojs
import { MsgExecuteContract } from 'osmojs/cosmwasm/wasm/v1/tx'
 
// neutronjs
import { MsgExecuteContract } from 'neutronjs/cosmwasm/wasm/v1/tx'
 
// All use the same encode pattern:
const encode = (p) =>
  MsgExecuteContract.encode(
    MsgExecuteContract.fromPartial({ ...p, funds: [...p.funds] }),
  ).finish()

Internal Behavior

  • createQueryAdapter uses Json.toBytes and Json.fromBytes for query encoding/decoding
  • createExecuteAdapter composes createQueryAdapter internally, then adds execute using Json.toBytes for the msg field
  • The adapter constructs MsgExecuteContract with typeUrl /cosmwasm.wasm.v1.MsgExecuteContract