CosmJS
repository·main·Indexed 20 days ago
https://github.com/cosmos/cosmjsA modular suite of TypeScript libraries for building JavaScript-based clients for the Cosmos ecosystem, including web apps, browser extensions, and server-side tools. The suite includes packages such as @cosmjs/stargate for Cosmos SDK interaction, @cosmjs/cosmwasm for smart contract interaction, @cosmjs/crypto for low-level cryptographic functionality, @cosmjs/encoding for Bech32 and Hex utilities, and @cosmjs/proto-signing for protobuf-based transaction signing.
What's inside CosmJS
- @cosmjs/stargate is a client library designed for interacting with the Cosmos SDK (version 0.40 and above). It provides the core functionality needed to communicate with Cosmos-based blockchains via the Stargate interface.
Overview of @cosmjs/encoding
mainThe
@cosmjs/encodingpackage is a utility library that extends standard JavaScript encoding capabilities. It is not tied to specific blockchain products and provides:- Hex, Base64, and ASCII encoding/decoding for
Uint8Array. - Implementations that do not rely on the Node.js
Bufferglobal, making it compatible with various environments. - Improved error messages for invalid input compared to standard methods.
- Hex, Base64, and ASCII encoding/decoding for
Overview of @cosmjs/stream
main@cosmjs/stream provides helper methods and classes designed to assist with stream processing tasks within the CosmJS ecosystem.Overview of @cosmjs/utils
main@cosmjs/utils provides utility functions that are independent of specific blockchain applications. While these functions are primarily designed for use in testing environments, some utilities likesleepare also useful for general runtime applications.Overview of @cosmjs/cosmwasm
main@cosmjs/cosmwasm is an SDK designed for building CosmWasm clients. It provides the necessary tools to interact with CosmWasm smart contracts on Cosmos-based blockchains.Overview of CosmJS
mainCosmJS is a collection of JavaScript/TypeScript libraries designed for interacting with the Cosmos ecosystem. It supports a wide range of client solutions, including web applications, explorers, browser extensions, and server-side tools like faucets or scrapers. The project is developed in TypeScript and is designed to run in multiple environments.Overview of @cosmjs/json-rpc
main@cosmjs/json-rpc is a lightweight framework designed for implementing a JSON-RPC 2.0 compliant API. It provides the necessary primitives to build and structure JSON-RPC services according to the official specification.Overview of @cosmjs/crypto
main@cosmjs/crypto provides low-level cryptographic functionality. It acts as a curated collection of external cryptographic libraries, enhanced with type safety, additional correctness checks, and a simplified API. While it is a core dependency for other @cosmjs libraries, it is designed to be used independently in any application.Use @cosmjs/proto-signing for protobuf-based signing
mainThe@cosmjs/proto-signingpackage provides utilities for protobuf-based transaction signing, which is required for Cosmos SDK versions 0.40 and above. This follows the encoding standards defined in ADR-020 and the three levels of proto encoding used by the Cosmos SDK.Use @cosmjs/tendermint-rpc for type-safe Tendermint RPC interactions
mainThe
@cosmjs/tendermint-rpcpackage provides a type-safe wrapper around the Tendermint RPC API. It simplifies interactions by handling data transformations automatically:- Binary Data: All binary data is passed in and out as
Uint8Array. - Encoding/Decoding: The module manages hex and base64 encoding/decoding based on the specific field requirements and the version of Tendermint being used.
- Numeric Conversion: It handles the conversion of numbers to and from strings as required by the RPC interface.
- Binary Data: All binary data is passed in and out as
How the Faucet HD wallet works
mainThe faucet uses Hierarchical Deterministic (HD) paths to derive accounts from a single
FAUCET_MNEMONIC.- Account 0: The primary token holder account.
- Accounts 1 to
FAUCET_CONCURRENCY: Distributor accounts used to manage funds.
Common paths used by the faucet:
- IOV:
m/44'/234'/a' - Lisk:
m/44'/134'/a' - Cosmos:
m/44'/118'/0'/0/a
Where
ais the 0-based index of the account. You can access the token holder account using standard wallets (like Neuma) by providing the same mnemonic.Supported JS environments for CosmJS
mainCosmJS targets ES2020 and supports the following runtimes:
- Node.js 20+
- Modern browsers (Chromium, Firefox, Safari; excludes Internet Explorer and Edge Legacy).
- Browser extensions (Chromium, Firefox).
Note: CosmJS uses WebAssembly (Wasm) for certain cryptographic functions. If your environment does not support Wasm, contact the maintainers for potential swappable implementations.