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

cosmjs

SigningCosmWasmClient works directly with schemos — no adapter needed.

Execute + Query

import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate'
import { createTypedContract } from 'schemos'
import { cw20 } from 'schemos/schemas'
 
const client = await SigningCosmWasmClient.connectWithSigner(rpcEndpoint, signer)
const token = createTypedContract(client, contractAddress, cw20)
 
// Message names autocomplete, fields are type-checked
await token.execute(
  senderAddress,
  'transfer',
  { recipient: 'osmo1...', amount: '1000' },
  'auto',
)
 
// Return type inferred from response schema
const { 
const balance: string
balance
} = await token.query('balance', { address: 'osmo1...' })

Query-only

Use CosmWasmClient (no signing) for read-only access:

import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate'
import { createTypedContract } from 'schemos'
import { cw20 } from 'schemos/schemas'
 
const client = await CosmWasmClient.connect(rpcEndpoint)
 
const token = createTypedContract(client, 'osmo1...', {
  query: cw20.query,
  responses: cw20.responses,
})
 
// query() available with typed responses
const { 
const balance: string
balance
} = await token.query('balance', { address: 'osmo1...' })
// execute() does not exist on query-only contracts

Full Example

import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate'
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing'
import { GasPrice } from '@cosmjs/stargate'
import { createTypedContract } from 'schemos'
import { cw20 } from 'schemos/schemas'
 
// 1. Connect with cosmjs
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic)
const client = await SigningCosmWasmClient.connectWithSigner(
  rpcEndpoint,
  wallet,
  { gasPrice: GasPrice.fromString('0.025uosmo') },
)
 
// 2. Create typed contractno adapter needed
const token = createTypedContract(client, contractAddress, cw20)
 
// 3. Type-safe interactions
const [account] = await wallet.getAccounts()
await token.execute(
  account.address,
  'transfer',
  { recipient: 'osmo1...', amount: '1000' },
  'auto',
)
 
const { 
const balance: string
balance
} = await token.query('balance', { address: account.address })