npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@knstl/cosmosjs

v1.0.17

Published

A JavasScript Open Source Library for Konstellation Network

Downloads

7

Readme

CosmosJS - Cosmos JavaScript Library

Supports CosmosSDK v0.37.+

:star: Developed / Developing by Konstellation on CosmosJS

A JavaSript Open Source Library for Konstellation Network

This library supports cosmos address generation and verification. It enables you to create an offline signature functions of different types of transaction messages. It will eventually support all the other blockchains that are based on Tendermint in the future, such as IOV and others.

MIT NPM

Installation

In order to fully use this library, you need to run a local or remote full node and set up its rest server, which acts as an intermediary between the front-end and the full-node

NPM

npm install @konstellation/cosmosjs

Yarn

yarn add @konstellation/cosmosjs

Browser Distribution

CosmosJS supports browserify.

Import

Vue

import sdk from '@konstellation/cosmosjs';

NodeJS (WIP)

const sdk = require("@konstellation/cosmosjs");

Browser (WIP)

<script src='js/cosmosjs-bundle.js'></script>

Usage

Init network

const chain = sdk({
    apiUrl: 'http://localhost:1317',
    nodeUrl: 'http://localhost:26657',
    chainId: 'darchub',
});

Generate Cosmos account

const account = chain.generateAccount();

Import account from keystore or menmonic

const account = chain.importAccount({keystore, pass});

or

const account = chain.importAccount({mnemonic});

Recover Cosmos account from mnemonic

const mnemonic = "...";
const account = chain.recoverAccount(mnemonic);

Import Cosmos account from keystore

const account = chain.importAccountFromV3KeyStore(key, pass);

Export Cosmos account to keystore

const ks = chain.exportAccountToV3KeyStore(account, pass);

Get address

const address = account.getAddress();

Fetch node info

const { node_info } = await chain.fetchNodeInfo();

Fetch blockchain info

const { result } = await chain.fetchBlockchainInfo({
    minHeight,
    maxHeight,
    random: new Date().getTime(),
});

Fetch account info by address

const {result: {value}} = await chain.fetchAccount(address);
account.updateInfo(value);

Fetch balance of account by address

const balance = await chain.fetchAccountBalance(address);

Transfer DARC to destination address.

- Raw method

Build message

Make sure to input proper type, account number, and sequence of the cosmos account to generate StdSignMsg. You can get those account information on blockchain

const msg = chain.buildMsg({
    type: MsgSend.type,
    from: account.getAddress(),
    to: "...",
    amount: {amount, denom},	
});
Build transaction
const signMsg = chain.buildSignMsg(msg, {
    fee: {amount, denom},
    gas: 200000,
    memo: "",
    accountNumber: account.getAccountNumber(),
    sequence: account.getSequence()
});
Sign transaction
const stdTx = chain.signWithAccount(signMsg, account);

or

const stdTx = chain.sign(signMsg, account.getPrivateKey(), account.getPublicKey());

Broadcast transaction

const broadcastInfo = await chain.broadcastTx(stdTx, 'sync');
All in one
const broadcastInfo = await chain.buildSignBroadcast({
    type: MsgSend.type,
    from: account.getAddress(),
    to: '...',
    amount: {amount, denom},
}, {
    gas,
    memo,
    fee,
    accountNumber: account.getAccountNumber(),
    sequence: account.getSequence(),
    privateKey: account.getPrivateKey(),
    publicKey: account.getPublicKey(),
})

- Transfer method

const res = await chain.transfer({
    from: account.getAddress(),
    accountNumber: account.getAccountNumber(),
    sequence: account.getSequence(),
    privateKey: account.getPrivateKey(),
    publicKey: account.getPublicKey(),
    to: address,
    amount: {amount, denom},
    memo,
    fee: {amount, denom},
    gas,
});

- TransferFromAccount method

const res = await chain.transferWithAccount({
    from: account,
    to: address,
    amount: {amount, denom},
    memo,
    fee: {amount, denom},
    gas
});

Fetch total transactions count

const txsInfo = await chain.fetchTotalTransactionsCount();

Fetch all transactions

const txsInfo = await chain.fetchAllTransactions();

Fetch transactions where the address is a recipient

const txsInfo = await chain.fetchInboundTransactions(address, 100);

Fetch transaction where the address is a sender

const txsInfo = await chain.fetchOutboundTransactions(address, 100);

Fetch a transaction by hash in a committed block

const txInfo = await chain.fetchTransaction('FB2FCCCCA94B18E19C9D1A4DDA0DDF97E18E3A385C94A37AA95695E65F7364D5');

Search transactions

Genesis transactions are returned if the height parameter is set to zero, otherwise the transactions are searched for by events

const txs = await chain.searchTransactions({height: 0});

Delegate tokens to the validator

const res = await chain.delegateWithAccount({
    delegator,
    validatorAddr,
    amount: {amount: denom},
})

Redelegate tokens to the new validator

const res = await chain.redelegateWithAccount({
    delegator,
    validatorDstAddr,
    validatorSrcAddr,
    amount: {amount: denom},
})

Undelegate tokens from the validator

const res = await chain.undelegateWithAccount({
    delegator,
    validatorAddr,
    amount: {amount: denom},
})

Withdraw delegation rewards from the validator

const res = await chain.withdrawDelegationRewardWithAccount({
    delegator,
    validatorAddr,
})

Withdraw all delegation rewards from all delegations

const res = await chain.withdrawDelegationRewardsWithAccount({
    delegator,
})

Unjail validator

const res = await chain.unjailValidatorWithAccount({
    validator,
})

Perform custom request

const node_info = await chain.request('/node_info');
const req = await chain.request('/txs', {
    path: '/FB2FCCCCA94B18E19C9D1A4DDA0DDF97E18E3A385C94A37AA95695E65F7364D5'
});

This package also supports all available functions of LCD REST-SERVER

Supporting Message Types (Updating...)

  • cosmos-sdk/MsgSend
const stdSignMsg = chain.buildMsg({
    type: MsgSend.type,
    from: address,
    to: "...",
    amount: {amount, denom},
});
  • cosmos-sdk/MsgDelegate
const stdSignMsg = chain.buildMsg({
    type: MsgDelegate.type,
    delegatorAddr,
    validatorAddr,
    amount: {amount, denom},
});
  • cosmos-sdk/MsgBeginRedelegate
const stdSignMsg = chain.buildMsg({
    type: MsgBeginRedelegate.type,
    delegatorAddr,
    validatorDstAddr,
    validatorSrcAddr,
    amount: {amount, denom},
});
  • cosmos-sdk/MsgUndelegate
const stdSignMsg = chain.buildMsg({
    type: MsgUndelegate.type,
    amount: {amount, denom},
    delegatorAddr,
    validatorAddr,
});
  • cosmos-sdk/MsgWithdrawDelegationReward
const stdSignMsg = chain.buildMsg({
    type: MsgWithdrawDelegationReward.type,
    delegatorAddr,
    validatorAddr,
});
  • cosmos-sdk/MsgUnjail
const stdSignMsg = chain.buildMsg({
    type: MsgUnjail.type,
    validatorAddr,
});
  • cosmos-sdk/MsgSubmitProposal
const stdSignMsg = chain.buildMsg({
    type: MsgSubmitProposal.type,
    proposal_type: 'TextProposal',
    initialDeposit: {amount, denom},
    description,
    proposer,
    title,
});
  • cosmos-sdk/MsgDeposit
const stdSignMsg = chain.buildMsg({
    type: MsgDeposit.type,
    proposalId,
    depositorAddr,
    amount: {amount, denom},
});
  • cosmos-sdk/MsgVote
const stdSignMsg = chain.buildMsg({
    type: MsgVote.type,
    proposalId,
    voterAddr,
    option,
});

Documentation

This library is simple and easy to use. We don't have any formal documentation yet other than examples. Ask for help if our examples aren't enough to guide you

Contribution

  • Contributions, suggestions, improvements, and feature requests are always welcome

When opening a PR with a minor fix, make sure to add #trivial to the title/description of said PR.