CosmJS
CosmJS is the swiss army knife to power JavaScript based client solutions ranging from Web apps/explorers over browser extensions to server-side clients like faucets/scrapers in the Cosmos ecosystem.
"Cosm" stands for Cosmos and "JS" stands for runs everywhere – we actually develop in TypeScript.
Packages
CosmJS is a library that consists of many smaller npm packages within the @cosmjs namespace, a so called monorepo. Here are some of them to get an idea:
Package | Description | Latest version |
---|---|---|
@cosmjs/sdk38 | A client library for the Cosmos SDK 0.38 | |
@cosmjs/faucet | A faucet application for node.js | |
@cosmjs/cosmwasm | Client for chains with the CosmWasm module enabled | |
@cosmjs/crypto | Cryptography resources for blockchain projects | |
@cosmjs/encoding | Encoding helpers for blockchain projects | |
@cosmjs/math | Safe integers; decimals for handling financial amounts |
Modularity
We're pretty proud of the modularity and a clean dependency tree in this monorepo. This ensures software quality on our side and lets users pick exactly what they need. Here you see how everything fits together (every item is an npm package; right depends on left):
Supported JS environments
Currently the codebase supports the following environments:
- Node.js 10+
- Modern browsers (Chromium/Firefox/Safari, no IE or Edge)
- Browser extensions (Chromium/Firefox)
Our current JavaScript target standard is ES2017, giving us native async/wait support. We use WebAssembly to implement certain crypto.
We're happy to adjust this list according to users' needs as long as you don't ask for IE support. If your environment does not support Wasm, we can work on a solution with swapable implementations.
Development
Requires Node 10+. For best results, use yarn. The basic commands are:
yarn install
# compile the code
yarn build
# run unit tests
yarn test
# format and lint the code
yarn format && yarn lint
Integration tests
To run the entire test suite, you need to run a local blockchain to test against. We use wasmd for both CosmWasm tests and as a generic Cosmos SDK 0.38 blockchain. This should work on any Linux/OSX system with docker installed:
./scripts/wasmd/start.sh
./scripts/wasmd/init.sh
WASMD_ENABLED=1 yarn test
./scripts/wasmd/stop.sh