Skip to content

Repository files navigation

Cosmos Client

Installation

npm install @cryptech/cosmos-client

Usage

import{CosmosClient}from"@cryptech/cosmos-client";constclient=awaitCosmosClient.new({mnemonic: "your mnemonic",chainId: "your chain id",});// Get account infoconstaccount=awaitclient.getAccount("your account address");// Simulate a transaction to get gas estimate as StdFeeconststdFee=awaitclient.simulateFees(messagesAsEncodeObject);// Smart contract queryconstresponse=awaitclient.query("your smart contract address",{// query payload});// Smart contract transactionconsttxHash=awaitclient.tx("your smart contract address",{// tx payload});/** * Messages As EncodeObject *  * * The messagesAsEncodeObject is an array of objects that contain the following properties: * source: import { EncodeObject } from "@cosmjs/proto-signing"; * { typeUrl: string; value: any; } * * Example for a Smart Contract Execute Message (Using cosmjs-types/cosmwasm/wasm/v1/tx.proto) * { typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract", value: MsgExecuteContract.fromPartial({ sender: this.sender, contract: this.contractAddress, msg: toUtf8(JSON.stringify({ my_tx_message: { tx_props1, tx_props2 } })), funds: [{ denom: "uatom", amount: "1000000" }] }) } */// Sign and broadcast any messages in the same transactionconstresponse=awaitclient.signAndBroadcast(messagesAsEncodeObject,"your optional memo","your optional fee");// Sign transaction and return a TxRaw objectconstsignedTx=awaitclient.sign(messagesAsEncodeObject,"your optional memo","your optional fee");// Broadcast a signed TxRaw objectconstresponse=awaitclient.broadcast(signedTx);

By default, Cosmos Client will try to find the required chain info from the chain-registry. If you want to use a custom chain, you can pass the more options to the CosmosClient.new function.

client=awaitCosmosClient.new({chainId: process.env.CHAIN_ID,mnemonic: process.env.MNEMONIC,walletPrefix: process.env.WALLET_PREFIX,rpcEndpoint: process.env.RPC,gasPrice: process.env.GAS_PRICE,gasAdjustment: process.env.GAS_ADJUSTMENT,gasDenom: process.env.DENOM,coinType: process.env.COIN_TYPE,granter: process.env.GRANTER,});

About

A typescript cosmos client compatible with injective and cosmjs

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages