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

@bitsongjs/client

v2.4.0-beta.10

Published

Javascript API library for NodeJS and Web browsers to interact with the BitSong Blockchain

Downloads

36

Readme

📡 @bitsongjs/client

This package defines an query client and tx client to interact with the bitsong chain, inside it there are also the definitions of the proto and amino files.

Feature list:

  • Query client
  • Tx client
  • Proto definitions
  • Amino definitions (compatibility with ledgers)

🚀 Tech Stack

Typescript, Lerna, NX, CosmJS

⚙️ Build

Install dependencies

  yarn

Get bitsong proto files

yarn get-proto

Build bitsong proto files

yarn define-proto

Build

  yarn build

Run tests

  yarn test

📘 Examples

The library exposes one main TypeScript class: the BitsongClient class.

We suggest using the chain registry to get information about Bitsong, they also provide a npm package:

import { assets, chains, ibc } from 'chain-registry';

const chain = chains.find(({chain_name}) => chain_name==='bitsong');

console.log(chain);

const assetList = assets.find(({chain_name}) => chain_name==='bitsong');

console.log(assetList);

You can also get IBC denom and info by using the following npm package:

import { getIbcAssets } from '@chain-registry/utils';
import { assets, ibc } from 'chain-registry';

export const ibcMap = [
  ...getIbcAssets('osmosis', ibc, assets),
  ...getIbcAssets('juno', ibc, assets),
  ...getIbcAssets('bitsong', ibc, assets),
];

Here is an example of fetching the user's balance:

import { BitsongClient, Bech32PrefixAccAddr, MicroDenom } from '@bitsongjs/client';
import { QueryClientImpl as BankQueryClientImpl, QueryAllBalancesRequest } from '@bitsongjs/client/dist/codec/cosmos/bank/v1beta1/query';
import { lastValueFrom, switchMap } from 'rxjs';

const modules = {
  bank: BankQueryClientImpl,
}

const signer = await DirectSecp256k1HdWallet.fromMnemonic('YOUR MNEMONIC', {
  prefix: Bech32PrefixAccAddr,
  hdPaths: [stringToPath(getHdPath())],
});

const api = new BitsongClient<typeof modules>({
  connection: {
    type: 'tendermint',
    endpoints: ['<YOUR RPC URL>'],
    signer, // OfflineSigner from @cosmjs/proto-signing
  },
}, modules);

const [firstAccount] = await signer.getAccounts();
const myAddress = firstAccount.address;

const balancesResponse = await lastValueFrom(
  api.query.pipe(
    switchMap(query =>
      query.bank.AllBalances({
        $type: QueryAllBalancesRequest.$type,
        address: myAddress,
      }),
    ),
  ),
);

console.log(balancesResponse);
/*
    Prints example: `{
        "balances":[{"denom":"ubtsg","amount":"10000000000"}],
        "pagination":{"total":1}
    }`
*/

// Sign and broadcast a transaction with some x/bank MsgSend.
const msg = MsgSend.fromPartial({
  fromAddress: myAddress,
  toAddress: 'bitsong1...',
  amount: [{ amount: '1000000', denom: 'ubtsg' }],
});

// StdFee from @cosmjs/stargate
const fee = {
  amount: [
    {
      denom: MicroDenom,
      amount: '5000',
    },
  ],
  gas: '200000',
};

const txClient = await lastValueFrom(api.txClient);

const txBytes = await txClient.sign(
	myAddress,
	[msg],
	fee,
	'a memo text',
);

if (txBytes) {
	const deliverTxRes = await txClient.broadcast(txBytes);
}

👤 Authors

🆘 Support

For support, open an issue or join our Discord.

🔏 License

Copyright © 2022 BitSong.

This project is licensed by MIT License.