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,
): CosmWasmQueryClientParameters
| Parameter | Type | Description |
|---|---|---|
smartContractState | SmartContractStateFn | Telescope 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
| Parameter | Type | Description |
|---|---|---|
smartContractState | SmartContractStateFn | Telescope RPC query function |
signAndBroadcast | SignAndBroadcastFn | Signing client's broadcast method |
encodeMsgExecuteContract | EncodeMsgExecuteContractFn | Protobuf 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[]
}) => Uint8ArrayEncodes 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
createQueryAdapterusesJson.toBytesandJson.fromBytesfor query encoding/decodingcreateExecuteAdaptercomposescreateQueryAdapterinternally, then addsexecuteusingJson.toBytesfor the msg field- The adapter constructs
MsgExecuteContractwith typeUrl/cosmwasm.wasm.v1.MsgExecuteContract