Skip to main content
This guide walks you through installing CosmJS, connecting to a Cosmos SDK chain, querying on-chain state, and sending your first transaction.

Prerequisites

  • Node.js v22 or later
  • npm, yarn, or pnpm
  • A Cosmos SDK chain RPC endpoint (e.g. https://rpc.my-chain.network for the Cosmos Hub)
1

Install

2

Connect to a chain

Create a read-only client and verify the connection:
Find RPC endpoints for any Cosmos chain in the chain registry.
3

Query balances

Use the connected client to look up any account’s balance:
4

Create a signer

To send transactions you need a signer. You can create one from a mnemonic for development, or connect a browser wallet like Keplr in production.
Never hard-code or commit mnemonics. Use environment variables or a secrets manager.
5

Send tokens

Connect a signing client and broadcast a token transfer:
Setting fee to "auto" lets CosmJS simulate the transaction and estimate gas automatically. You can also pass an explicit StdFee object for fine-grained control.
6

Send arbitrary messages

For transactions beyond simple token transfers, construct message objects directly:

Next Steps

Clients

Understand read-only and signing client architecture.

Querying

Query balances, staking, governance, and custom modules.

Fees & Gas

Configure gas pricing, simulation, and fee calculation.

CosmWasm

Deploy, instantiate, and execute smart contracts.