![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@cosmjs/cosmwasm-stargate
Advanced tools
@cosmjs/cosmwasm-stargate is a JavaScript library that provides tools for interacting with CosmWasm smart contracts on the Cosmos blockchain. It allows developers to connect to a blockchain, query smart contracts, execute transactions, and manage accounts.
Connect to a Blockchain
This feature allows you to connect to a Cosmos blockchain using a specified RPC endpoint. The code sample demonstrates how to create a StargateClient instance to interact with the blockchain.
const { StargateClient } = require('@cosmjs/stargate');
const rpcEndpoint = "https://rpc.cosmos.network";
const client = await StargateClient.connect(rpcEndpoint);
Query Smart Contracts
This feature allows you to query a smart contract for data. The code sample shows how to use the CosmWasmClient to query a contract for a specific piece of information.
const { CosmWasmClient } = require('@cosmjs/cosmwasm-stargate');
const client = await CosmWasmClient.connect(rpcEndpoint);
const contractAddress = "cosmos1...";
const queryResult = await client.queryContractSmart(contractAddress, { get_count: {} });
Execute Transactions
This feature allows you to execute transactions on a smart contract. The code sample demonstrates how to use a SigningCosmWasmClient to send a transaction that calls a contract's method.
const { SigningCosmWasmClient } = require('@cosmjs/cosmwasm-stargate');
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic);
const client = await SigningCosmWasmClient.connectWithSigner(rpcEndpoint, wallet);
const result = await client.execute(senderAddress, contractAddress, { increment: {} }, fee);
Manage Accounts
This feature allows you to manage accounts, including creating wallets and retrieving account information. The code sample shows how to create a wallet from a mnemonic and get account details.
const { DirectSecp256k1HdWallet } = require('@cosmjs/proto-signing');
const mnemonic = "...";
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic);
const [firstAccount] = await wallet.getAccounts();
cosmos-client is a JavaScript library for interacting with the Cosmos SDK-based blockchains. It provides similar functionalities for connecting to a blockchain and managing transactions, but it may not have specific support for CosmWasm smart contracts like @cosmjs/cosmwasm-stargate.
An SDK to build CosmWasm clients.
CosmWasm | x/wasm | @cosmjs/cosmwasm-stargate |
---|---|---|
0.16-1.0.0-beta | 0.21-0.23 | ^0.28.0 |
0.16-1.0.0-beta | 0.21-0.23 | ^0.27.0 |
0.16-1.0.0-beta | 0.18-0.20 | ^0.26.0 |
0.14 | 0.16 | ^0.25.0 |
0.13 | 0.14-0.15 | ^0.24.0 |
Updating Hackatom development contract in src/testdata/contract.json
:
cd packages/cosmwasm-stargate
export HACKATOM_URL=https://github.com/CosmWasm/cosmwasm/releases/download/v1.0.0-beta/hackatom.wasm
echo "{\"// source\": \"$HACKATOM_URL\", \"data\": \"$(curl -sS --location $HACKATOM_URL | base64 | tr -d '[:space:]')\" }" | jq > src/testdata/contract.json
This package is part of the cosmjs repository, licensed under the Apache License 2.0 (see NOTICE and LICENSE).
FAQs
CosmWasm SDK
The npm package @cosmjs/cosmwasm-stargate receives a total of 1,966 weekly downloads. As such, @cosmjs/cosmwasm-stargate popularity was classified as popular.
We found that @cosmjs/cosmwasm-stargate demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.