What is @cosmjs/cosmwasm-stargate?
@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.
What are @cosmjs/cosmwasm-stargate's main functionalities?
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();
Other packages similar to @cosmjs/cosmwasm-stargate
cosmos-client
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.
@cosmjs/cosmwasm-stargate
![npm version](https://img.shields.io/npm/v/@cosmjs/cosmwasm-stargate.svg)
An SDK to build CosmWasm clients.
Compatibility
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 |
Development
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
License
This package is part of the cosmjs repository, licensed under the Apache License
2.0 (see NOTICE and
LICENSE).